blob: 3dc6653c3b421a53901d76475daf7bb1488d0174 [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;
35 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);
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 Goeltzenleuchterca472ab2016-02-01 20:09:00 -0700172 float queue_priorities[] = {0.0};
Jesse Hallb1471272016-01-17 21:36:58 -0800173 const VkDeviceQueueCreateInfo queue_create_info = {
174 .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
175 .queueFamilyIndex = 0,
176 .queueCount = 1,
Courtney Goeltzenleuchterca472ab2016-02-01 20:09:00 -0700177 queue_priorities
Jesse Hallb1471272016-01-17 21:36:58 -0800178 };
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700179 // 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 Hallb1471272016-01-17 21:36:58 -0800193 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 Wud0bba372016-02-22 11:41:27 +0800199 .enabledLayerCount = (options.validate) ? num_layers : 0,
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700200 .ppEnabledLayerNames = kValidationLayers,
Jesse Hallb1471272016-01-17 21:36:58 -0800201 .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 Wud0bba372016-02-22 11:41:27 +0800209void GatherInfo(VulkanInfo* info, const Options& options) {
Jesse Hall09559b52016-01-07 21:50:19 -0800210 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 Hallae3b70d2016-01-17 22:05:29 -0800231 const char* kDesiredExtensions[] = {
232 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
Jesse Hall4da3bd62016-01-16 22:14:40 -0800233 };
Jesse Hallae3b70d2016-01-17 22:05:29 -0800234 const char*
235 extensions[sizeof(kDesiredExtensions) / sizeof(kDesiredExtensions[0])];
Jesse Hall4da3bd62016-01-16 22:14:40 -0800236 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 Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700245 // 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 Hall09559b52016-01-07 21:50:19 -0800260 const VkInstanceCreateInfo create_info = {
261 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
Jesse Hall4da3bd62016-01-16 22:14:40 -0800262 .enabledExtensionCount = num_extensions,
263 .ppEnabledExtensionNames = extensions,
Chia-I Wud0bba372016-02-22 11:41:27 +0800264 .enabledLayerCount = (options.validate) ? num_layers : 0,
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700265 .ppEnabledLayerNames = kValidationLayers,
Jesse Hall09559b52016-01-07 21:50:19 -0800266 };
Jesse Hall4da3bd62016-01-16 22:14:40 -0800267 VkInstance instance;
Jesse Hall09559b52016-01-07 21:50:19 -0800268 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 Hallb1471272016-01-17 21:36:58 -0800285 for (size_t i = 0; i < gpus.size(); i++)
Chia-I Wud0bba372016-02-22 11:41:27 +0800286 GatherGpuInfo(gpus[i], options, info->gpus.at(i));
Jesse Hall09559b52016-01-07 21:50:19 -0800287
288 vkDestroyInstance(instance, nullptr);
289}
290
291// ----------------------------------------------------------------------------
292
Jesse Hall38cb8402016-01-18 03:41:35 -0800293const size_t kMaxIndent = 8;
294const size_t kIndentSize = 3;
295std::array<char, kMaxIndent * kIndentSize + 1> kIndent;
296const 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 Hallc1ab3032016-01-04 07:26:53 -0800307uint32_t ExtractMajorVersion(uint32_t version) {
308 return (version >> 22) & 0x3FF;
309}
310uint32_t ExtractMinorVersion(uint32_t version) {
311 return (version >> 12) & 0x3FF;
312}
313uint32_t ExtractPatchVersion(uint32_t version) {
314 return (version >> 0) & 0xFFF;
315}
316
Jesse Hall04f4f472015-08-16 19:51:04 -0700317const 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 Hall09559b52016-01-07 21:50:19 -0800334void PrintExtensions(const std::vector<VkExtensionProperties>& extensions,
Jesse Hall38cb8402016-01-18 03:41:35 -0800335 const Options& /*options*/,
336 size_t indent) {
Jesse Hall09559b52016-01-07 21:50:19 -0800337 for (const auto& e : extensions)
Jesse Hall38cb8402016-01-18 03:41:35 -0800338 printf("%s%s (v%u)\n", Indent(indent), e.extensionName, e.specVersion);
Jesse Hall09559b52016-01-07 21:50:19 -0800339}
Jesse Hallc1ab3032016-01-04 07:26:53 -0800340
Jesse Hallaa410942016-01-17 13:07:10 -0800341void PrintLayers(
342 const std::vector<VkLayerProperties>& layers,
343 const std::vector<std::vector<VkExtensionProperties>> extensions,
Jesse Hall38cb8402016-01-18 03:41:35 -0800344 const Options& options,
345 size_t indent) {
Jesse Hallaa410942016-01-17 13:07:10 -0800346 for (size_t i = 0; i < layers.size(); i++) {
Jesse Hall38cb8402016-01-18 03:41:35 -0800347 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 Hallaa410942016-01-17 13:07:10 -0800361 }
362}
363
Jesse Hall38cb8402016-01-18 03:41:35 -0800364void PrintGpuInfo(const GpuInfo& info, const Options& options, size_t indent) {
Jesse Hall04f4f472015-08-16 19:51:04 -0700365 VkResult result;
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100366 std::ostringstream strbuf;
Jesse Hall04f4f472015-08-16 19:51:04 -0700367
Jesse Hall38cb8402016-01-18 03:41:35 -0800368 printf("%s\"%s\" (%s) %u.%u.%u/%#x [%04x:%04x]\n", Indent(indent),
Jesse Hall09559b52016-01-07 21:50:19 -0800369 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 Hall73ab0ac2015-08-25 15:09:15 +0100376
Jesse Hall09559b52016-01-07 21:50:19 -0800377 for (uint32_t heap = 0; heap < info.memory.memoryHeapCount; heap++) {
378 if ((info.memory.memoryHeaps[heap].flags &
Jesse Halld1af8122015-11-29 23:50:38 -0800379 VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0)
380 strbuf << "DEVICE_LOCAL";
Jesse Hall38cb8402016-01-18 03:41:35 -0800381 printf("%sHeap %u: %" PRIu64 " MiB (0x%" PRIx64 " B) %s\n",
382 Indent(indent + 1), heap,
Jesse Hall00f10fe2016-02-08 21:20:20 -0800383 info.memory.memoryHeaps[heap].size / 0x100000,
Jesse Hall09559b52016-01-07 21:50:19 -0800384 info.memory.memoryHeaps[heap].size, strbuf.str().c_str());
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100385 strbuf.str(std::string());
386
Jesse Hall09559b52016-01-07 21:50:19 -0800387 for (uint32_t type = 0; type < info.memory.memoryTypeCount; type++) {
388 if (info.memory.memoryTypes[type].heapIndex != heap)
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100389 continue;
390 VkMemoryPropertyFlags flags =
Jesse Hall09559b52016-01-07 21:50:19 -0800391 info.memory.memoryTypes[type].propertyFlags;
Jesse Halld1af8122015-11-29 23:50:38 -0800392 if ((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0)
Jesse Hall1f91d392015-12-11 16:28:44 -0800393 strbuf << " DEVICE_LOCAL";
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100394 if ((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
Jesse Hall1f91d392015-12-11 16:28:44 -0800395 strbuf << " HOST_VISIBLE";
Jesse Halld1af8122015-11-29 23:50:38 -0800396 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 Hall73ab0ac2015-08-25 15:09:15 +0100400 if ((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0)
401 strbuf << " LAZILY_ALLOCATED";
Jesse Hall38cb8402016-01-18 03:41:35 -0800402 printf("%sType %u:%s\n", Indent(indent + 2), type,
403 strbuf.str().c_str());
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100404 strbuf.str(std::string());
405 }
406 }
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700407
Jesse Hall09559b52016-01-07 21:50:19 -0800408 for (uint32_t family = 0; family < info.queue_families.size(); family++) {
409 const VkQueueFamilyProperties& qprops = info.queue_families[family];
Jesse Hall8966bf42016-01-16 17:26:48 -0800410 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 Hall38cb8402016-01-18 03:41:35 -0800418 "%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 Hall8966bf42016-01-16 17:26:48 -0800423 qprops.minImageTransferGranularity.width,
424 qprops.minImageTransferGranularity.height,
425 qprops.minImageTransferGranularity.depth);
Jesse Hallb1471272016-01-17 21:36:58 -0800426 }
Jesse Hall6e4ab312016-01-07 22:26:20 -0800427
Jesse Hallc5cec282016-01-18 04:01:10 -0800428 // 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 Hall38cb8402016-01-18 03:41:35 -0800487 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 Hall04f4f472015-08-16 19:51:04 -0700493}
494
Jesse Hall38cb8402016-01-18 03:41:35 -0800495void PrintInfo(const VulkanInfo& info, const Options& options) {
Jesse Hall09559b52016-01-07 21:50:19 -0800496 std::ostringstream strbuf;
Jesse Hall38cb8402016-01-18 03:41:35 -0800497 size_t indent = 0;
Jesse Hall09559b52016-01-07 21:50:19 -0800498
Jesse Hall38cb8402016-01-18 03:41:35 -0800499 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 Hall09559b52016-01-07 21:50:19 -0800505
Jesse Hall38cb8402016-01-18 03:41:35 -0800506 printf("%sPhysicalDevices [%zu]:\n", Indent(indent), info.gpus.size());
Jesse Hall09559b52016-01-07 21:50:19 -0800507 for (const auto& gpu : info.gpus)
Jesse Hall38cb8402016-01-18 03:41:35 -0800508 PrintGpuInfo(gpu, options, indent + 1);
Jesse Hallc1ab3032016-01-04 07:26:53 -0800509}
510
Jesse Hall04f4f472015-08-16 19:51:04 -0700511} // namespace
512
Jesse Hall09559b52016-01-07 21:50:19 -0800513// ----------------------------------------------------------------------------
514
Jesse Hall38cb8402016-01-18 03:41:35 -0800515int main(int argc, char const* argv[]) {
Courtney Goeltzenleuchterc2a77092016-02-08 20:31:46 -0700516 static volatile bool startup_pause = false;
Jesse Hall38cb8402016-01-18 03:41:35 -0800517 Options options = {
518 .layer_description = false, .layer_extensions = false,
Chia-I Wud0bba372016-02-22 11:41:27 +0800519 .validate = false,
Jesse Hall38cb8402016-01-18 03:41:35 -0800520 };
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 Wud0bba372016-02-22 11:41:27 +0800529 } else if (strcmp(argv[argi], "-validate") == 0) {
530 options.validate = true;
Courtney Goeltzenleuchterc2a77092016-02-08 20:31:46 -0700531 } else if (strcmp(argv[argi], "-debug_pause") == 0) {
532 startup_pause = true;
Jesse Hall38cb8402016-01-18 03:41:35 -0800533 }
534 }
535
Courtney Goeltzenleuchterc2a77092016-02-08 20:31:46 -0700536 while (startup_pause) {
537 sleep(0);
538 }
539
Jesse Hallc1ab3032016-01-04 07:26:53 -0800540 VulkanInfo info;
Chia-I Wud0bba372016-02-22 11:41:27 +0800541 GatherInfo(&info, options);
Jesse Hall38cb8402016-01-18 03:41:35 -0800542 PrintInfo(info, options);
Jesse Hall04f4f472015-08-16 19:51:04 -0700543 return 0;
544}