blob: d8dd01be2b78ed448894df253ea4f530c5bf412a [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
Jesse Hall09559b52016-01-07 21:50:19 -080032struct GpuInfo {
33 VkPhysicalDeviceProperties properties;
34 VkPhysicalDeviceMemoryProperties memory;
Jesse Hallb1471272016-01-17 21:36:58 -080035 VkPhysicalDeviceFeatures features;
Jesse Hall09559b52016-01-07 21:50:19 -080036 std::vector<VkQueueFamilyProperties> queue_families;
Jesse Hall6e4ab312016-01-07 22:26:20 -080037 std::vector<VkExtensionProperties> extensions;
38 std::vector<VkLayerProperties> layers;
39 std::vector<std::vector<VkExtensionProperties>> layer_extensions;
Jesse Hall09559b52016-01-07 21:50:19 -080040};
41struct VulkanInfo {
42 std::vector<VkExtensionProperties> extensions;
43 std::vector<VkLayerProperties> layers;
44 std::vector<std::vector<VkExtensionProperties>> layer_extensions;
45 std::vector<GpuInfo> gpus;
46};
47
48// ----------------------------------------------------------------------------
49
Jesse Hall04f4f472015-08-16 19:51:04 -070050[[noreturn]] void die(const char* proc, VkResult result) {
51 const char* result_str;
52 switch (result) {
53 // clang-format off
54 case VK_SUCCESS: result_str = "VK_SUCCESS"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070055 case VK_NOT_READY: result_str = "VK_NOT_READY"; break;
56 case VK_TIMEOUT: result_str = "VK_TIMEOUT"; break;
57 case VK_EVENT_SET: result_str = "VK_EVENT_SET"; break;
58 case VK_EVENT_RESET: result_str = "VK_EVENT_RESET"; break;
59 case VK_INCOMPLETE: result_str = "VK_INCOMPLETE"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070060 case VK_ERROR_OUT_OF_HOST_MEMORY: result_str = "VK_ERROR_OUT_OF_HOST_MEMORY"; break;
61 case VK_ERROR_OUT_OF_DEVICE_MEMORY: result_str = "VK_ERROR_OUT_OF_DEVICE_MEMORY"; break;
Jesse Hall5ae3abb2015-10-08 14:00:22 -070062 case VK_ERROR_INITIALIZATION_FAILED: result_str = "VK_ERROR_INITIALIZATION_FAILED"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070063 case VK_ERROR_DEVICE_LOST: result_str = "VK_ERROR_DEVICE_LOST"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070064 case VK_ERROR_MEMORY_MAP_FAILED: result_str = "VK_ERROR_MEMORY_MAP_FAILED"; break;
Jesse Hall5ae3abb2015-10-08 14:00:22 -070065 case VK_ERROR_LAYER_NOT_PRESENT: result_str = "VK_ERROR_LAYER_NOT_PRESENT"; break;
66 case VK_ERROR_EXTENSION_NOT_PRESENT: result_str = "VK_ERROR_EXTENSION_NOT_PRESENT"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070067 case VK_ERROR_INCOMPATIBLE_DRIVER: result_str = "VK_ERROR_INCOMPATIBLE_DRIVER"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070068 default: result_str = "<unknown VkResult>"; break;
69 // clang-format on
70 }
71 fprintf(stderr, "%s failed: %s (%d)\n", proc, result_str, result);
72 exit(1);
73}
74
Jesse Hall4da3bd62016-01-16 22:14:40 -080075bool HasExtension(const std::vector<VkExtensionProperties>& extensions,
76 const char* name) {
77 return std::find_if(extensions.cbegin(), extensions.cend(),
78 [=](const VkExtensionProperties& prop) {
79 return strcmp(prop.extensionName, name) == 0;
80 }) != extensions.end();
81}
82
Jesse Hall09559b52016-01-07 21:50:19 -080083void EnumerateInstanceExtensions(
84 const char* layer_name,
85 std::vector<VkExtensionProperties>* extensions) {
86 VkResult result;
87 uint32_t count;
88 result =
89 vkEnumerateInstanceExtensionProperties(layer_name, &count, nullptr);
90 if (result != VK_SUCCESS)
91 die("vkEnumerateInstanceExtensionProperties (count)", result);
92 do {
93 extensions->resize(count);
94 result = vkEnumerateInstanceExtensionProperties(layer_name, &count,
95 extensions->data());
96 } while (result == VK_INCOMPLETE);
97 if (result != VK_SUCCESS)
98 die("vkEnumerateInstanceExtensionProperties (data)", result);
99}
100
Jesse Hall6e4ab312016-01-07 22:26:20 -0800101void EnumerateDeviceExtensions(VkPhysicalDevice gpu,
102 const char* layer_name,
103 std::vector<VkExtensionProperties>* extensions) {
104 VkResult result;
105 uint32_t count;
106 result =
107 vkEnumerateDeviceExtensionProperties(gpu, layer_name, &count, nullptr);
108 if (result != VK_SUCCESS)
109 die("vkEnumerateDeviceExtensionProperties (count)", result);
110 do {
111 extensions->resize(count);
112 result = vkEnumerateDeviceExtensionProperties(gpu, layer_name, &count,
113 extensions->data());
114 } while (result == VK_INCOMPLETE);
115 if (result != VK_SUCCESS)
116 die("vkEnumerateDeviceExtensionProperties (data)", result);
117}
118
Jesse Hallb1471272016-01-17 21:36:58 -0800119void GatherGpuInfo(VkPhysicalDevice gpu, GpuInfo& info) {
120 VkResult result;
121 uint32_t count;
122
123 vkGetPhysicalDeviceProperties(gpu, &info.properties);
124 vkGetPhysicalDeviceMemoryProperties(gpu, &info.memory);
125 vkGetPhysicalDeviceFeatures(gpu, &info.features);
126
127 vkGetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr);
128 info.queue_families.resize(count);
129 vkGetPhysicalDeviceQueueFamilyProperties(gpu, &count,
130 info.queue_families.data());
131
132 result = vkEnumerateDeviceLayerProperties(gpu, &count, nullptr);
133 if (result != VK_SUCCESS)
134 die("vkEnumerateDeviceLayerProperties (count)", result);
135 do {
136 info.layers.resize(count);
137 result =
138 vkEnumerateDeviceLayerProperties(gpu, &count, info.layers.data());
139 } while (result == VK_INCOMPLETE);
140 if (result != VK_SUCCESS)
141 die("vkEnumerateDeviceLayerProperties (data)", result);
142 info.layer_extensions.resize(info.layers.size());
143
144 EnumerateDeviceExtensions(gpu, nullptr, &info.extensions);
145 for (size_t i = 0; i < info.layers.size(); i++) {
146 EnumerateDeviceExtensions(gpu, info.layers[i].layerName,
147 &info.layer_extensions[i]);
148 }
149
150 const std::array<const char*, 1> kDesiredExtensions = {
151 {VK_KHR_SWAPCHAIN_EXTENSION_NAME},
152 };
153 const char* extensions[kDesiredExtensions.size()];
154 uint32_t num_extensions = 0;
155 for (const auto& desired_ext : kDesiredExtensions) {
156 bool available = HasExtension(info.extensions, desired_ext);
157 for (size_t i = 0; !available && i < info.layer_extensions.size(); i++)
158 available = HasExtension(info.layer_extensions[i], desired_ext);
159 if (available)
160 extensions[num_extensions++] = desired_ext;
161 }
162
163 VkDevice device;
Courtney Goeltzenleuchterca472ab2016-02-01 20:09:00 -0700164 float queue_priorities[] = {0.0};
Jesse Hallb1471272016-01-17 21:36:58 -0800165 const VkDeviceQueueCreateInfo queue_create_info = {
166 .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
167 .queueFamilyIndex = 0,
168 .queueCount = 1,
Courtney Goeltzenleuchterca472ab2016-02-01 20:09:00 -0700169 queue_priorities
Jesse Hallb1471272016-01-17 21:36:58 -0800170 };
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700171 // clang-format off
172 const char *kValidationLayers[] = {
173 "VK_LAYER_GOOGLE_threading",
174 "VK_LAYER_LUNARG_device_limits",
175 "VK_LAYER_LUNARG_draw_state",
176 "VK_LAYER_LUNARG_image",
177 "VK_LAYER_LUNARG_mem_tracker",
178 "VK_LAYER_LUNARG_object_tracker",
179 "VK_LAYER_LUNARG_param_checker",
180 "VK_LAYER_LUNARG_swapchain",
181 "VK_LAYER_GOOGLE_unique_objects"
182 };
183 // clang-format on
184 uint32_t num_layers = sizeof(kValidationLayers) / sizeof(char*);
Jesse Hallb1471272016-01-17 21:36:58 -0800185 const VkDeviceCreateInfo create_info = {
186 .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
187 .queueCreateInfoCount = 1,
188 .pQueueCreateInfos = &queue_create_info,
189 .enabledExtensionCount = num_extensions,
190 .ppEnabledExtensionNames = extensions,
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700191 .enabledLayerCount = num_layers,
192 .ppEnabledLayerNames = kValidationLayers,
Jesse Hallb1471272016-01-17 21:36:58 -0800193 .pEnabledFeatures = &info.features,
194 };
195 result = vkCreateDevice(gpu, &create_info, nullptr, &device);
196 if (result != VK_SUCCESS)
197 die("vkCreateDevice", result);
198 vkDestroyDevice(device, nullptr);
199}
200
Jesse Hall09559b52016-01-07 21:50:19 -0800201void GatherInfo(VulkanInfo* info) {
202 VkResult result;
203 uint32_t count;
204
205 result = vkEnumerateInstanceLayerProperties(&count, nullptr);
206 if (result != VK_SUCCESS)
207 die("vkEnumerateInstanceLayerProperties (count)", result);
208 do {
209 info->layers.resize(count);
210 result =
211 vkEnumerateInstanceLayerProperties(&count, info->layers.data());
212 } while (result == VK_INCOMPLETE);
213 if (result != VK_SUCCESS)
214 die("vkEnumerateInstanceLayerProperties (data)", result);
215 info->layer_extensions.resize(info->layers.size());
216
217 EnumerateInstanceExtensions(nullptr, &info->extensions);
218 for (size_t i = 0; i < info->layers.size(); i++) {
219 EnumerateInstanceExtensions(info->layers[i].layerName,
220 &info->layer_extensions[i]);
221 }
222
Jesse Hallae3b70d2016-01-17 22:05:29 -0800223 const char* kDesiredExtensions[] = {
224 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
Jesse Hall4da3bd62016-01-16 22:14:40 -0800225 };
Jesse Hallae3b70d2016-01-17 22:05:29 -0800226 const char*
227 extensions[sizeof(kDesiredExtensions) / sizeof(kDesiredExtensions[0])];
Jesse Hall4da3bd62016-01-16 22:14:40 -0800228 uint32_t num_extensions = 0;
229 for (const auto& desired_ext : kDesiredExtensions) {
230 bool available = HasExtension(info->extensions, desired_ext);
231 for (size_t i = 0; !available && i < info->layer_extensions.size(); i++)
232 available = HasExtension(info->layer_extensions[i], desired_ext);
233 if (available)
234 extensions[num_extensions++] = desired_ext;
235 }
236
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700237 // clang-format off
238 const char *kValidationLayers[] = {
239 "VK_LAYER_GOOGLE_threading",
240 "VK_LAYER_LUNARG_device_limits",
241 "VK_LAYER_LUNARG_draw_state",
242 "VK_LAYER_LUNARG_image",
243 "VK_LAYER_LUNARG_mem_tracker",
244 "VK_LAYER_LUNARG_object_tracker",
245 "VK_LAYER_LUNARG_param_checker",
246 "VK_LAYER_LUNARG_swapchain",
247 "VK_LAYER_GOOGLE_unique_objects"
248 };
249 // clang-format on
250 uint32_t num_layers = sizeof(kValidationLayers) / sizeof(char*);
251
Jesse Hall09559b52016-01-07 21:50:19 -0800252 const VkInstanceCreateInfo create_info = {
253 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
Jesse Hall4da3bd62016-01-16 22:14:40 -0800254 .enabledExtensionCount = num_extensions,
255 .ppEnabledExtensionNames = extensions,
Courtney Goeltzenleuchterb1e7d592016-02-08 20:31:25 -0700256 .enabledLayerCount = num_layers,
257 .ppEnabledLayerNames = kValidationLayers,
Jesse Hall09559b52016-01-07 21:50:19 -0800258 };
Jesse Hall4da3bd62016-01-16 22:14:40 -0800259 VkInstance instance;
Jesse Hall09559b52016-01-07 21:50:19 -0800260 result = vkCreateInstance(&create_info, nullptr, &instance);
261 if (result != VK_SUCCESS)
262 die("vkCreateInstance", result);
263
264 uint32_t num_gpus;
265 result = vkEnumeratePhysicalDevices(instance, &num_gpus, nullptr);
266 if (result != VK_SUCCESS)
267 die("vkEnumeratePhysicalDevices (count)", result);
268 std::vector<VkPhysicalDevice> gpus(num_gpus, VK_NULL_HANDLE);
269 do {
270 gpus.resize(num_gpus, VK_NULL_HANDLE);
271 result = vkEnumeratePhysicalDevices(instance, &num_gpus, gpus.data());
272 } while (result == VK_INCOMPLETE);
273 if (result != VK_SUCCESS)
274 die("vkEnumeratePhysicalDevices (data)", result);
275
276 info->gpus.resize(num_gpus);
Jesse Hallb1471272016-01-17 21:36:58 -0800277 for (size_t i = 0; i < gpus.size(); i++)
278 GatherGpuInfo(gpus[i], info->gpus.at(i));
Jesse Hall09559b52016-01-07 21:50:19 -0800279
280 vkDestroyInstance(instance, nullptr);
281}
282
283// ----------------------------------------------------------------------------
284
Jesse Hall38cb8402016-01-18 03:41:35 -0800285struct Options {
286 bool layer_description;
287 bool layer_extensions;
288};
289
290const size_t kMaxIndent = 8;
291const size_t kIndentSize = 3;
292std::array<char, kMaxIndent * kIndentSize + 1> kIndent;
293const char* Indent(size_t n) {
294 static bool initialized = false;
295 if (!initialized) {
296 kIndent.fill(' ');
297 kIndent.back() = '\0';
298 initialized = true;
299 }
300 return kIndent.data() +
301 (kIndent.size() - (kIndentSize * std::min(n, kMaxIndent) + 1));
302}
303
Jesse Hallc1ab3032016-01-04 07:26:53 -0800304uint32_t ExtractMajorVersion(uint32_t version) {
305 return (version >> 22) & 0x3FF;
306}
307uint32_t ExtractMinorVersion(uint32_t version) {
308 return (version >> 12) & 0x3FF;
309}
310uint32_t ExtractPatchVersion(uint32_t version) {
311 return (version >> 0) & 0xFFF;
312}
313
Jesse Hall04f4f472015-08-16 19:51:04 -0700314const char* VkPhysicalDeviceTypeStr(VkPhysicalDeviceType type) {
315 switch (type) {
316 case VK_PHYSICAL_DEVICE_TYPE_OTHER:
317 return "OTHER";
318 case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
319 return "INTEGRATED_GPU";
320 case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
321 return "DISCRETE_GPU";
322 case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
323 return "VIRTUAL_GPU";
324 case VK_PHYSICAL_DEVICE_TYPE_CPU:
325 return "CPU";
326 default:
327 return "<UNKNOWN>";
328 }
329}
330
Jesse Hall09559b52016-01-07 21:50:19 -0800331void PrintExtensions(const std::vector<VkExtensionProperties>& extensions,
Jesse Hall38cb8402016-01-18 03:41:35 -0800332 const Options& /*options*/,
333 size_t indent) {
Jesse Hall09559b52016-01-07 21:50:19 -0800334 for (const auto& e : extensions)
Jesse Hall38cb8402016-01-18 03:41:35 -0800335 printf("%s%s (v%u)\n", Indent(indent), e.extensionName, e.specVersion);
Jesse Hall09559b52016-01-07 21:50:19 -0800336}
Jesse Hallc1ab3032016-01-04 07:26:53 -0800337
Jesse Hallaa410942016-01-17 13:07:10 -0800338void PrintLayers(
339 const std::vector<VkLayerProperties>& layers,
340 const std::vector<std::vector<VkExtensionProperties>> extensions,
Jesse Hall38cb8402016-01-18 03:41:35 -0800341 const Options& options,
342 size_t indent) {
Jesse Hallaa410942016-01-17 13:07:10 -0800343 for (size_t i = 0; i < layers.size(); i++) {
Jesse Hall38cb8402016-01-18 03:41:35 -0800344 printf("%s%s %u.%u.%u/%u\n", Indent(indent), layers[i].layerName,
345 ExtractMajorVersion(layers[i].specVersion),
346 ExtractMinorVersion(layers[i].specVersion),
347 ExtractPatchVersion(layers[i].specVersion),
348 layers[i].implementationVersion);
349 if (options.layer_description)
350 printf("%s%s\n", Indent(indent + 1), layers[i].description);
351 if (options.layer_extensions && !extensions[i].empty()) {
352 if (!extensions[i].empty()) {
353 printf("%sExtensions [%zu]:\n", Indent(indent + 1),
354 extensions[i].size());
355 PrintExtensions(extensions[i], options, indent + 2);
356 }
357 }
Jesse Hallaa410942016-01-17 13:07:10 -0800358 }
359}
360
Jesse Hall38cb8402016-01-18 03:41:35 -0800361void PrintGpuInfo(const GpuInfo& info, const Options& options, size_t indent) {
Jesse Hall04f4f472015-08-16 19:51:04 -0700362 VkResult result;
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100363 std::ostringstream strbuf;
Jesse Hall04f4f472015-08-16 19:51:04 -0700364
Jesse Hall38cb8402016-01-18 03:41:35 -0800365 printf("%s\"%s\" (%s) %u.%u.%u/%#x [%04x:%04x]\n", Indent(indent),
Jesse Hall09559b52016-01-07 21:50:19 -0800366 info.properties.deviceName,
367 VkPhysicalDeviceTypeStr(info.properties.deviceType),
368 ExtractMajorVersion(info.properties.apiVersion),
369 ExtractMinorVersion(info.properties.apiVersion),
370 ExtractPatchVersion(info.properties.apiVersion),
371 info.properties.driverVersion, info.properties.vendorID,
372 info.properties.deviceID);
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100373
Jesse Hall09559b52016-01-07 21:50:19 -0800374 for (uint32_t heap = 0; heap < info.memory.memoryHeapCount; heap++) {
375 if ((info.memory.memoryHeaps[heap].flags &
Jesse Halld1af8122015-11-29 23:50:38 -0800376 VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0)
377 strbuf << "DEVICE_LOCAL";
Jesse Hall38cb8402016-01-18 03:41:35 -0800378 printf("%sHeap %u: %" PRIu64 " MiB (0x%" PRIx64 " B) %s\n",
379 Indent(indent + 1), heap,
Jesse Hall00f10fe2016-02-08 21:20:20 -0800380 info.memory.memoryHeaps[heap].size / 0x100000,
Jesse Hall09559b52016-01-07 21:50:19 -0800381 info.memory.memoryHeaps[heap].size, strbuf.str().c_str());
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100382 strbuf.str(std::string());
383
Jesse Hall09559b52016-01-07 21:50:19 -0800384 for (uint32_t type = 0; type < info.memory.memoryTypeCount; type++) {
385 if (info.memory.memoryTypes[type].heapIndex != heap)
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100386 continue;
387 VkMemoryPropertyFlags flags =
Jesse Hall09559b52016-01-07 21:50:19 -0800388 info.memory.memoryTypes[type].propertyFlags;
Jesse Halld1af8122015-11-29 23:50:38 -0800389 if ((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0)
Jesse Hall1f91d392015-12-11 16:28:44 -0800390 strbuf << " DEVICE_LOCAL";
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100391 if ((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
Jesse Hall1f91d392015-12-11 16:28:44 -0800392 strbuf << " HOST_VISIBLE";
Jesse Halld1af8122015-11-29 23:50:38 -0800393 if ((flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0)
394 strbuf << " COHERENT";
395 if ((flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) != 0)
396 strbuf << " CACHED";
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100397 if ((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0)
398 strbuf << " LAZILY_ALLOCATED";
Jesse Hall38cb8402016-01-18 03:41:35 -0800399 printf("%sType %u:%s\n", Indent(indent + 2), type,
400 strbuf.str().c_str());
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100401 strbuf.str(std::string());
402 }
403 }
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700404
Jesse Hall09559b52016-01-07 21:50:19 -0800405 for (uint32_t family = 0; family < info.queue_families.size(); family++) {
406 const VkQueueFamilyProperties& qprops = info.queue_families[family];
Jesse Hall8966bf42016-01-16 17:26:48 -0800407 VkQueueFlags flags = qprops.queueFlags;
408 char flags_str[5];
409 flags_str[0] = (flags & VK_QUEUE_GRAPHICS_BIT) ? 'G' : '_';
410 flags_str[1] = (flags & VK_QUEUE_COMPUTE_BIT) ? 'C' : '_';
411 flags_str[2] = (flags & VK_QUEUE_TRANSFER_BIT) ? 'T' : '_';
412 flags_str[3] = (flags & VK_QUEUE_SPARSE_BINDING_BIT) ? 'S' : '_';
413 flags_str[4] = '\0';
414 printf(
Jesse Hall38cb8402016-01-18 03:41:35 -0800415 "%sQueue Family %u: %ux %s\n"
416 "%stimestampValidBits: %ub\n"
417 "%sminImageTransferGranularity: (%u,%u,%u)\n",
418 Indent(indent + 1), family, qprops.queueCount, flags_str,
419 Indent(indent + 2), qprops.timestampValidBits, Indent(indent + 2),
Jesse Hall8966bf42016-01-16 17:26:48 -0800420 qprops.minImageTransferGranularity.width,
421 qprops.minImageTransferGranularity.height,
422 qprops.minImageTransferGranularity.depth);
Jesse Hallb1471272016-01-17 21:36:58 -0800423 }
Jesse Hall6e4ab312016-01-07 22:26:20 -0800424
Jesse Hallc5cec282016-01-18 04:01:10 -0800425 // clang-format off
426 printf("%sFeatures:\n", Indent(indent + 1));
427 printf("%srobustBufferAccess: %s\n", Indent(indent + 2), info.features.robustBufferAccess ? "YES" : "NO");
428 printf("%sfullDrawIndexUint32: %s\n", Indent(indent + 2), info.features.fullDrawIndexUint32 ? "YES" : "NO");
429 printf("%simageCubeArray: %s\n", Indent(indent + 2), info.features.imageCubeArray ? "YES" : "NO");
430 printf("%sindependentBlend: %s\n", Indent(indent + 2), info.features.independentBlend ? "YES" : "NO");
431 printf("%sgeometryShader: %s\n", Indent(indent + 2), info.features.geometryShader ? "YES" : "NO");
432 printf("%stessellationShader: %s\n", Indent(indent + 2), info.features.tessellationShader ? "YES" : "NO");
433 printf("%ssampleRateShading: %s\n", Indent(indent + 2), info.features.sampleRateShading ? "YES" : "NO");
434 printf("%sdualSrcBlend: %s\n", Indent(indent + 2), info.features.dualSrcBlend ? "YES" : "NO");
435 printf("%slogicOp: %s\n", Indent(indent + 2), info.features.logicOp ? "YES" : "NO");
436 printf("%smultiDrawIndirect: %s\n", Indent(indent + 2), info.features.multiDrawIndirect ? "YES" : "NO");
437 printf("%sdrawIndirectFirstInstance: %s\n", Indent(indent + 2), info.features.drawIndirectFirstInstance ? "YES" : "NO");
438 printf("%sdepthClamp: %s\n", Indent(indent + 2), info.features.depthClamp ? "YES" : "NO");
439 printf("%sdepthBiasClamp: %s\n", Indent(indent + 2), info.features.depthBiasClamp ? "YES" : "NO");
440 printf("%sfillModeNonSolid: %s\n", Indent(indent + 2), info.features.fillModeNonSolid ? "YES" : "NO");
441 printf("%sdepthBounds: %s\n", Indent(indent + 2), info.features.depthBounds ? "YES" : "NO");
442 printf("%swideLines: %s\n", Indent(indent + 2), info.features.wideLines ? "YES" : "NO");
443 printf("%slargePoints: %s\n", Indent(indent + 2), info.features.largePoints ? "YES" : "NO");
444 printf("%salphaToOne: %s\n", Indent(indent + 2), info.features.alphaToOne ? "YES" : "NO");
445 printf("%smultiViewport: %s\n", Indent(indent + 2), info.features.multiViewport ? "YES" : "NO");
446 printf("%ssamplerAnisotropy: %s\n", Indent(indent + 2), info.features.samplerAnisotropy ? "YES" : "NO");
447 printf("%stextureCompressionETC2: %s\n", Indent(indent + 2), info.features.textureCompressionETC2 ? "YES" : "NO");
448 printf("%stextureCompressionASTC_LDR: %s\n", Indent(indent + 2), info.features.textureCompressionASTC_LDR ? "YES" : "NO");
449 printf("%stextureCompressionBC: %s\n", Indent(indent + 2), info.features.textureCompressionBC ? "YES" : "NO");
450 printf("%socclusionQueryPrecise: %s\n", Indent(indent + 2), info.features.occlusionQueryPrecise ? "YES" : "NO");
451 printf("%spipelineStatisticsQuery: %s\n", Indent(indent + 2), info.features.pipelineStatisticsQuery ? "YES" : "NO");
452 printf("%svertexPipelineStoresAndAtomics: %s\n", Indent(indent + 2), info.features.vertexPipelineStoresAndAtomics ? "YES" : "NO");
453 printf("%sfragmentStoresAndAtomics: %s\n", Indent(indent + 2), info.features.fragmentStoresAndAtomics ? "YES" : "NO");
454 printf("%sshaderTessellationAndGeometryPointSize: %s\n", Indent(indent + 2), info.features.shaderTessellationAndGeometryPointSize ? "YES" : "NO");
455 printf("%sshaderImageGatherExtended: %s\n", Indent(indent + 2), info.features.shaderImageGatherExtended ? "YES" : "NO");
456 printf("%sshaderStorageImageExtendedFormats: %s\n", Indent(indent + 2), info.features.shaderStorageImageExtendedFormats ? "YES" : "NO");
457 printf("%sshaderStorageImageMultisample: %s\n", Indent(indent + 2), info.features.shaderStorageImageMultisample ? "YES" : "NO");
458 printf("%sshaderStorageImageReadWithoutFormat: %s\n", Indent(indent + 2), info.features.shaderStorageImageReadWithoutFormat ? "YES" : "NO");
459 printf("%sshaderStorageImageWriteWithoutFormat: %s\n", Indent(indent + 2), info.features.shaderStorageImageWriteWithoutFormat ? "YES" : "NO");
460 printf("%sshaderUniformBufferArrayDynamicIndexing: %s\n", Indent(indent + 2), info.features.shaderUniformBufferArrayDynamicIndexing ? "YES" : "NO");
461 printf("%sshaderSampledImageArrayDynamicIndexing: %s\n", Indent(indent + 2), info.features.shaderSampledImageArrayDynamicIndexing ? "YES" : "NO");
462 printf("%sshaderStorageBufferArrayDynamicIndexing: %s\n", Indent(indent + 2), info.features.shaderStorageBufferArrayDynamicIndexing ? "YES" : "NO");
463 printf("%sshaderStorageImageArrayDynamicIndexing: %s\n", Indent(indent + 2), info.features.shaderStorageImageArrayDynamicIndexing ? "YES" : "NO");
464 printf("%sshaderClipDistance: %s\n", Indent(indent + 2), info.features.shaderClipDistance ? "YES" : "NO");
465 printf("%sshaderCullDistance: %s\n", Indent(indent + 2), info.features.shaderCullDistance ? "YES" : "NO");
466 printf("%sshaderFloat64: %s\n", Indent(indent + 2), info.features.shaderFloat64 ? "YES" : "NO");
467 printf("%sshaderInt64: %s\n", Indent(indent + 2), info.features.shaderInt64 ? "YES" : "NO");
468 printf("%sshaderInt16: %s\n", Indent(indent + 2), info.features.shaderInt16 ? "YES" : "NO");
469 printf("%sshaderResourceResidency: %s\n", Indent(indent + 2), info.features.shaderResourceResidency ? "YES" : "NO");
470 printf("%sshaderResourceMinLod: %s\n", Indent(indent + 2), info.features.shaderResourceMinLod ? "YES" : "NO");
471 printf("%ssparseBinding: %s\n", Indent(indent + 2), info.features.sparseBinding ? "YES" : "NO");
472 printf("%ssparseResidencyBuffer: %s\n", Indent(indent + 2), info.features.sparseResidencyBuffer ? "YES" : "NO");
473 printf("%ssparseResidencyImage2D: %s\n", Indent(indent + 2), info.features.sparseResidencyImage2D ? "YES" : "NO");
474 printf("%ssparseResidencyImage3D: %s\n", Indent(indent + 2), info.features.sparseResidencyImage3D ? "YES" : "NO");
475 printf("%ssparseResidency2Samples: %s\n", Indent(indent + 2), info.features.sparseResidency2Samples ? "YES" : "NO");
476 printf("%ssparseResidency4Samples: %s\n", Indent(indent + 2), info.features.sparseResidency4Samples ? "YES" : "NO");
477 printf("%ssparseResidency8Samples: %s\n", Indent(indent + 2), info.features.sparseResidency8Samples ? "YES" : "NO");
478 printf("%ssparseResidency16Samples: %s\n", Indent(indent + 2), info.features.sparseResidency16Samples ? "YES" : "NO");
479 printf("%ssparseResidencyAliased: %s\n", Indent(indent + 2), info.features.sparseResidencyAliased ? "YES" : "NO");
480 printf("%svariableMultisampleRate: %s\n", Indent(indent + 2), info.features.variableMultisampleRate ? "YES" : "NO");
481 printf("%sinheritedQueries: %s\n", Indent(indent + 2), info.features.inheritedQueries ? "YES" : "NO");
482 // clang-format on
483
Jesse Hall38cb8402016-01-18 03:41:35 -0800484 printf("%sExtensions [%zu]:\n", Indent(indent + 1), info.extensions.size());
485 if (!info.extensions.empty())
486 PrintExtensions(info.extensions, options, indent + 2);
487 printf("%sLayers [%zu]:\n", Indent(indent + 1), info.layers.size());
488 if (!info.layers.empty())
489 PrintLayers(info.layers, info.layer_extensions, options, indent + 2);
Jesse Hall04f4f472015-08-16 19:51:04 -0700490}
491
Jesse Hall38cb8402016-01-18 03:41:35 -0800492void PrintInfo(const VulkanInfo& info, const Options& options) {
Jesse Hall09559b52016-01-07 21:50:19 -0800493 std::ostringstream strbuf;
Jesse Hall38cb8402016-01-18 03:41:35 -0800494 size_t indent = 0;
Jesse Hall09559b52016-01-07 21:50:19 -0800495
Jesse Hall38cb8402016-01-18 03:41:35 -0800496 printf("%sInstance Extensions [%zu]:\n", Indent(indent),
497 info.extensions.size());
498 PrintExtensions(info.extensions, options, indent + 1);
499 printf("%sInstance Layers [%zu]:\n", Indent(indent), info.layers.size());
500 if (!info.layers.empty())
501 PrintLayers(info.layers, info.layer_extensions, options, indent + 1);
Jesse Hall09559b52016-01-07 21:50:19 -0800502
Jesse Hall38cb8402016-01-18 03:41:35 -0800503 printf("%sPhysicalDevices [%zu]:\n", Indent(indent), info.gpus.size());
Jesse Hall09559b52016-01-07 21:50:19 -0800504 for (const auto& gpu : info.gpus)
Jesse Hall38cb8402016-01-18 03:41:35 -0800505 PrintGpuInfo(gpu, options, indent + 1);
Jesse Hallc1ab3032016-01-04 07:26:53 -0800506}
507
Jesse Hall04f4f472015-08-16 19:51:04 -0700508} // namespace
509
Jesse Hall09559b52016-01-07 21:50:19 -0800510// ----------------------------------------------------------------------------
511
Jesse Hall38cb8402016-01-18 03:41:35 -0800512int main(int argc, char const* argv[]) {
513 Options options = {
514 .layer_description = false, .layer_extensions = false,
515 };
516 for (int argi = 1; argi < argc; argi++) {
517 if (strcmp(argv[argi], "-v") == 0) {
518 options.layer_description = true;
519 options.layer_extensions = true;
520 } else if (strcmp(argv[argi], "-layer_description") == 0) {
521 options.layer_description = true;
522 } else if (strcmp(argv[argi], "-layer_extensions") == 0) {
523 options.layer_extensions = true;
524 }
525 }
526
Jesse Hallc1ab3032016-01-04 07:26:53 -0800527 VulkanInfo info;
528 GatherInfo(&info);
Jesse Hall38cb8402016-01-18 03:41:35 -0800529 PrintInfo(info, options);
Jesse Hall04f4f472015-08-16 19:51:04 -0700530 return 0;
531}