Home | History | Annotate | Download | only in tools
      1 /*
      2  * Copyright 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <algorithm>
     18 #include <array>
     19 #include <inttypes.h>
     20 #include <stdlib.h>
     21 #include <sstream>
     22 #include <vector>
     23 
     24 #include <vulkan/vulkan.h>
     25 
     26 #define LOG_TAG "vkinfo"
     27 #include <log/log.h>
     28 
     29 namespace {
     30 
     31 struct Options {
     32     bool layer_description;
     33     bool layer_extensions;
     34     bool unsupported_features;
     35     bool validate;
     36 };
     37 
     38 struct GpuInfo {
     39     VkPhysicalDeviceProperties properties;
     40     VkPhysicalDeviceMemoryProperties memory;
     41     VkPhysicalDeviceFeatures features;
     42     std::vector<VkQueueFamilyProperties> queue_families;
     43     std::vector<VkExtensionProperties> extensions;
     44     std::vector<VkLayerProperties> layers;
     45     std::vector<std::vector<VkExtensionProperties>> layer_extensions;
     46 };
     47 struct VulkanInfo {
     48     std::vector<VkExtensionProperties> extensions;
     49     std::vector<VkLayerProperties> layers;
     50     std::vector<std::vector<VkExtensionProperties>> layer_extensions;
     51     std::vector<GpuInfo> gpus;
     52 };
     53 
     54 // ----------------------------------------------------------------------------
     55 
     56 [[noreturn]] void die(const char* proc, VkResult result) {
     57     const char* result_str;
     58     switch (result) {
     59         // clang-format off
     60         case VK_SUCCESS: result_str = "VK_SUCCESS"; break;
     61         case VK_NOT_READY: result_str = "VK_NOT_READY"; break;
     62         case VK_TIMEOUT: result_str = "VK_TIMEOUT"; break;
     63         case VK_EVENT_SET: result_str = "VK_EVENT_SET"; break;
     64         case VK_EVENT_RESET: result_str = "VK_EVENT_RESET"; break;
     65         case VK_INCOMPLETE: result_str = "VK_INCOMPLETE"; break;
     66         case VK_ERROR_OUT_OF_HOST_MEMORY: result_str = "VK_ERROR_OUT_OF_HOST_MEMORY"; break;
     67         case VK_ERROR_OUT_OF_DEVICE_MEMORY: result_str = "VK_ERROR_OUT_OF_DEVICE_MEMORY"; break;
     68         case VK_ERROR_INITIALIZATION_FAILED: result_str = "VK_ERROR_INITIALIZATION_FAILED"; break;
     69         case VK_ERROR_DEVICE_LOST: result_str = "VK_ERROR_DEVICE_LOST"; break;
     70         case VK_ERROR_MEMORY_MAP_FAILED: result_str = "VK_ERROR_MEMORY_MAP_FAILED"; break;
     71         case VK_ERROR_LAYER_NOT_PRESENT: result_str = "VK_ERROR_LAYER_NOT_PRESENT"; break;
     72         case VK_ERROR_EXTENSION_NOT_PRESENT: result_str = "VK_ERROR_EXTENSION_NOT_PRESENT"; break;
     73         case VK_ERROR_INCOMPATIBLE_DRIVER: result_str = "VK_ERROR_INCOMPATIBLE_DRIVER"; break;
     74         default: result_str = "<unknown VkResult>"; break;
     75             // clang-format on
     76     }
     77     fprintf(stderr, "%s failed: %s (%d)\n", proc, result_str, result);
     78     exit(1);
     79 }
     80 
     81 bool HasExtension(const std::vector<VkExtensionProperties>& extensions,
     82                   const char* name) {
     83     return std::find_if(extensions.cbegin(), extensions.cend(),
     84                         [=](const VkExtensionProperties& prop) {
     85                             return strcmp(prop.extensionName, name) == 0;
     86                         }) != extensions.end();
     87 }
     88 
     89 void EnumerateInstanceExtensions(
     90     const char* layer_name,
     91     std::vector<VkExtensionProperties>* extensions) {
     92     VkResult result;
     93     uint32_t count;
     94     result =
     95         vkEnumerateInstanceExtensionProperties(layer_name, &count, nullptr);
     96     if (result != VK_SUCCESS)
     97         die("vkEnumerateInstanceExtensionProperties (count)", result);
     98     do {
     99         extensions->resize(count);
    100         result = vkEnumerateInstanceExtensionProperties(layer_name, &count,
    101                                                         extensions->data());
    102     } while (result == VK_INCOMPLETE);
    103     if (result != VK_SUCCESS)
    104         die("vkEnumerateInstanceExtensionProperties (data)", result);
    105 }
    106 
    107 void EnumerateDeviceExtensions(VkPhysicalDevice gpu,
    108                                const char* layer_name,
    109                                std::vector<VkExtensionProperties>* extensions) {
    110     VkResult result;
    111     uint32_t count;
    112     result =
    113         vkEnumerateDeviceExtensionProperties(gpu, layer_name, &count, nullptr);
    114     if (result != VK_SUCCESS)
    115         die("vkEnumerateDeviceExtensionProperties (count)", result);
    116     do {
    117         extensions->resize(count);
    118         result = vkEnumerateDeviceExtensionProperties(gpu, layer_name, &count,
    119                                                       extensions->data());
    120     } while (result == VK_INCOMPLETE);
    121     if (result != VK_SUCCESS)
    122         die("vkEnumerateDeviceExtensionProperties (data)", result);
    123 }
    124 
    125 void GatherGpuInfo(VkPhysicalDevice gpu,
    126                    const Options &options,
    127                    GpuInfo& info) {
    128     VkResult result;
    129     uint32_t count;
    130 
    131     vkGetPhysicalDeviceProperties(gpu, &info.properties);
    132     vkGetPhysicalDeviceMemoryProperties(gpu, &info.memory);
    133     vkGetPhysicalDeviceFeatures(gpu, &info.features);
    134 
    135     vkGetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr);
    136     info.queue_families.resize(count);
    137     vkGetPhysicalDeviceQueueFamilyProperties(gpu, &count,
    138                                              info.queue_families.data());
    139 
    140     result = vkEnumerateDeviceLayerProperties(gpu, &count, nullptr);
    141     if (result != VK_SUCCESS)
    142         die("vkEnumerateDeviceLayerProperties (count)", result);
    143     do {
    144         info.layers.resize(count);
    145         result =
    146             vkEnumerateDeviceLayerProperties(gpu, &count, info.layers.data());
    147     } while (result == VK_INCOMPLETE);
    148     if (result != VK_SUCCESS)
    149         die("vkEnumerateDeviceLayerProperties (data)", result);
    150     info.layer_extensions.resize(info.layers.size());
    151 
    152     EnumerateDeviceExtensions(gpu, nullptr, &info.extensions);
    153     for (size_t i = 0; i < info.layers.size(); i++) {
    154         EnumerateDeviceExtensions(gpu, info.layers[i].layerName,
    155                                   &info.layer_extensions[i]);
    156     }
    157 
    158     const std::array<const char*, 1> kDesiredExtensions = {
    159         {VK_KHR_SWAPCHAIN_EXTENSION_NAME},
    160     };
    161     const char* extensions[kDesiredExtensions.size()];
    162     uint32_t num_extensions = 0;
    163     for (const auto& desired_ext : kDesiredExtensions) {
    164         bool available = HasExtension(info.extensions, desired_ext);
    165         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         }
    170         if (available)
    171             extensions[num_extensions++] = desired_ext;
    172     }
    173 
    174     VkDevice device;
    175     float queue_priorities[] = {0.0};
    176     const VkDeviceQueueCreateInfo queue_create_info = {
    177         .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
    178         .queueFamilyIndex = 0,
    179         .queueCount = 1,
    180         queue_priorities
    181     };
    182     // clang-format off
    183     const char *kValidationLayers[] = {
    184         "VK_LAYER_GOOGLE_threading",
    185         "VK_LAYER_LUNARG_parameter_validation",
    186         "VK_LAYER_LUNARG_device_limits",
    187         "VK_LAYER_LUNARG_object_tracker",
    188         "VK_LAYER_LUNARG_image",
    189         "VK_LAYER_LUNARG_core_validation",
    190         "VK_LAYER_LUNARG_swapchain",
    191         "VK_LAYER_GOOGLE_unique_objects"
    192     };
    193     // clang-format on
    194     uint32_t num_layers = sizeof(kValidationLayers) / sizeof(char*);
    195     const VkDeviceCreateInfo create_info = {
    196         .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
    197         .queueCreateInfoCount = 1,
    198         .pQueueCreateInfos = &queue_create_info,
    199         .enabledExtensionCount = num_extensions,
    200         .ppEnabledExtensionNames = extensions,
    201         .enabledLayerCount = (options.validate) ? num_layers : 0,
    202         .ppEnabledLayerNames = kValidationLayers,
    203         .pEnabledFeatures = &info.features,
    204     };
    205     result = vkCreateDevice(gpu, &create_info, nullptr, &device);
    206     if (result != VK_SUCCESS)
    207         die("vkCreateDevice", result);
    208     vkDestroyDevice(device, nullptr);
    209 }
    210 
    211 void GatherInfo(VulkanInfo* info, const Options& options) {
    212     VkResult result;
    213     uint32_t count;
    214 
    215     result = vkEnumerateInstanceLayerProperties(&count, nullptr);
    216     if (result != VK_SUCCESS)
    217         die("vkEnumerateInstanceLayerProperties (count)", result);
    218     do {
    219         info->layers.resize(count);
    220         result =
    221             vkEnumerateInstanceLayerProperties(&count, info->layers.data());
    222     } while (result == VK_INCOMPLETE);
    223     if (result != VK_SUCCESS)
    224         die("vkEnumerateInstanceLayerProperties (data)", result);
    225     info->layer_extensions.resize(info->layers.size());
    226 
    227     EnumerateInstanceExtensions(nullptr, &info->extensions);
    228     for (size_t i = 0; i < info->layers.size(); i++) {
    229         EnumerateInstanceExtensions(info->layers[i].layerName,
    230                                     &info->layer_extensions[i]);
    231     }
    232 
    233     const char* kDesiredExtensions[] = {
    234         VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
    235     };
    236     const char*
    237         extensions[sizeof(kDesiredExtensions) / sizeof(kDesiredExtensions[0])];
    238     uint32_t num_extensions = 0;
    239     for (const auto& desired_ext : kDesiredExtensions) {
    240         bool available = HasExtension(info->extensions, desired_ext);
    241         if (options.validate) {
    242             for (size_t i = 0; !available && i < info->layer_extensions.size();
    243                  i++)
    244                 available =
    245                     HasExtension(info->layer_extensions[i], desired_ext);
    246         }
    247         if (available)
    248             extensions[num_extensions++] = desired_ext;
    249     }
    250 
    251     // clang-format off
    252     const char *kValidationLayers[] = {
    253         "VK_LAYER_GOOGLE_threading",
    254         "VK_LAYER_LUNARG_parameter_validation",
    255         "VK_LAYER_LUNARG_device_limits",
    256         "VK_LAYER_LUNARG_object_tracker",
    257         "VK_LAYER_LUNARG_image",
    258         "VK_LAYER_LUNARG_core_validation",
    259         "VK_LAYER_LUNARG_swapchain",
    260         "VK_LAYER_GOOGLE_unique_objects"
    261     };
    262     // clang-format on
    263     uint32_t num_layers = sizeof(kValidationLayers) / sizeof(char*);
    264 
    265     const VkApplicationInfo application_info = {
    266         .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
    267         .pApplicationName = "vkinfo",
    268         .applicationVersion = 0,
    269         .pEngineName = "vkinfo",
    270         .engineVersion = 0,
    271         .apiVersion = VK_API_VERSION_1_0,
    272     };
    273     const VkInstanceCreateInfo create_info = {
    274         .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
    275         .pApplicationInfo = &application_info,
    276         .enabledExtensionCount = num_extensions,
    277         .ppEnabledExtensionNames = extensions,
    278         .enabledLayerCount = (options.validate) ? num_layers : 0,
    279         .ppEnabledLayerNames = kValidationLayers,
    280     };
    281     VkInstance instance;
    282     result = vkCreateInstance(&create_info, nullptr, &instance);
    283     if (result != VK_SUCCESS)
    284         die("vkCreateInstance", result);
    285 
    286     uint32_t num_gpus;
    287     result = vkEnumeratePhysicalDevices(instance, &num_gpus, nullptr);
    288     if (result != VK_SUCCESS)
    289         die("vkEnumeratePhysicalDevices (count)", result);
    290     std::vector<VkPhysicalDevice> gpus(num_gpus, VK_NULL_HANDLE);
    291     do {
    292         gpus.resize(num_gpus, VK_NULL_HANDLE);
    293         result = vkEnumeratePhysicalDevices(instance, &num_gpus, gpus.data());
    294     } while (result == VK_INCOMPLETE);
    295     if (result != VK_SUCCESS)
    296         die("vkEnumeratePhysicalDevices (data)", result);
    297 
    298     info->gpus.resize(num_gpus);
    299     for (size_t i = 0; i < gpus.size(); i++)
    300         GatherGpuInfo(gpus[i], options, info->gpus.at(i));
    301 
    302     vkDestroyInstance(instance, nullptr);
    303 }
    304 
    305 // ----------------------------------------------------------------------------
    306 
    307 const size_t kMaxIndent = 8;
    308 const size_t kIndentSize = 3;
    309 std::array<char, kMaxIndent * kIndentSize + 1> kIndent;
    310 const char* Indent(size_t n) {
    311     static bool initialized = false;
    312     if (!initialized) {
    313         kIndent.fill(' ');
    314         kIndent.back() = '\0';
    315         initialized = true;
    316     }
    317     return kIndent.data() +
    318            (kIndent.size() - (kIndentSize * std::min(n, kMaxIndent) + 1));
    319 }
    320 
    321 const char* VkPhysicalDeviceTypeStr(VkPhysicalDeviceType type) {
    322     switch (type) {
    323         case VK_PHYSICAL_DEVICE_TYPE_OTHER:
    324             return "OTHER";
    325         case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
    326             return "INTEGRATED_GPU";
    327         case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
    328             return "DISCRETE_GPU";
    329         case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
    330             return "VIRTUAL_GPU";
    331         case VK_PHYSICAL_DEVICE_TYPE_CPU:
    332             return "CPU";
    333         default:
    334             return "<UNKNOWN>";
    335     }
    336 }
    337 
    338 void PrintExtensions(const std::vector<VkExtensionProperties>& extensions,
    339                      const Options& /*options*/,
    340                      size_t indent) {
    341     for (const auto& e : extensions)
    342         printf("%s%s (v%u)\n", Indent(indent), e.extensionName, e.specVersion);
    343 }
    344 
    345 void PrintLayers(
    346     const std::vector<VkLayerProperties>& layers,
    347     const std::vector<std::vector<VkExtensionProperties>> extensions,
    348     const Options& options,
    349     size_t indent) {
    350     for (size_t i = 0; i < layers.size(); i++) {
    351         printf("%s%s %u.%u.%u/%u\n", Indent(indent), layers[i].layerName,
    352                VK_VERSION_MAJOR(layers[i].specVersion),
    353                VK_VERSION_MINOR(layers[i].specVersion),
    354                VK_VERSION_PATCH(layers[i].specVersion),
    355                layers[i].implementationVersion);
    356         if (options.layer_description)
    357             printf("%s%s\n", Indent(indent + 1), layers[i].description);
    358         if (options.layer_extensions && !extensions[i].empty()) {
    359             if (!extensions[i].empty()) {
    360                 printf("%sExtensions [%zu]:\n", Indent(indent + 1),
    361                        extensions[i].size());
    362                 PrintExtensions(extensions[i], options, indent + 2);
    363             }
    364         }
    365     }
    366 }
    367 
    368 void PrintAllFeatures(const char* indent,
    369                       const VkPhysicalDeviceFeatures& features) {
    370     // clang-format off
    371     printf("%srobustBufferAccess: %s\n", indent, features.robustBufferAccess ? "YES" : "NO");
    372     printf("%sfullDrawIndexUint32: %s\n", indent, features.fullDrawIndexUint32 ? "YES" : "NO");
    373     printf("%simageCubeArray: %s\n", indent, features.imageCubeArray ? "YES" : "NO");
    374     printf("%sindependentBlend: %s\n", indent, features.independentBlend ? "YES" : "NO");
    375     printf("%sgeometryShader: %s\n", indent, features.geometryShader ? "YES" : "NO");
    376     printf("%stessellationShader: %s\n", indent, features.tessellationShader ? "YES" : "NO");
    377     printf("%ssampleRateShading: %s\n", indent, features.sampleRateShading ? "YES" : "NO");
    378     printf("%sdualSrcBlend: %s\n", indent, features.dualSrcBlend ? "YES" : "NO");
    379     printf("%slogicOp: %s\n", indent, features.logicOp ? "YES" : "NO");
    380     printf("%smultiDrawIndirect: %s\n", indent, features.multiDrawIndirect ? "YES" : "NO");
    381     printf("%sdrawIndirectFirstInstance: %s\n", indent, features.drawIndirectFirstInstance ? "YES" : "NO");
    382     printf("%sdepthClamp: %s\n", indent, features.depthClamp ? "YES" : "NO");
    383     printf("%sdepthBiasClamp: %s\n", indent, features.depthBiasClamp ? "YES" : "NO");
    384     printf("%sfillModeNonSolid: %s\n", indent, features.fillModeNonSolid ? "YES" : "NO");
    385     printf("%sdepthBounds: %s\n", indent, features.depthBounds ? "YES" : "NO");
    386     printf("%swideLines: %s\n", indent, features.wideLines ? "YES" : "NO");
    387     printf("%slargePoints: %s\n", indent, features.largePoints ? "YES" : "NO");
    388     printf("%salphaToOne: %s\n", indent, features.alphaToOne ? "YES" : "NO");
    389     printf("%smultiViewport: %s\n", indent, features.multiViewport ? "YES" : "NO");
    390     printf("%ssamplerAnisotropy: %s\n", indent, features.samplerAnisotropy ? "YES" : "NO");
    391     printf("%stextureCompressionETC2: %s\n", indent, features.textureCompressionETC2 ? "YES" : "NO");
    392     printf("%stextureCompressionASTC_LDR: %s\n", indent, features.textureCompressionASTC_LDR ? "YES" : "NO");
    393     printf("%stextureCompressionBC: %s\n", indent, features.textureCompressionBC ? "YES" : "NO");
    394     printf("%socclusionQueryPrecise: %s\n", indent, features.occlusionQueryPrecise ? "YES" : "NO");
    395     printf("%spipelineStatisticsQuery: %s\n", indent, features.pipelineStatisticsQuery ? "YES" : "NO");
    396     printf("%svertexPipelineStoresAndAtomics: %s\n", indent, features.vertexPipelineStoresAndAtomics ? "YES" : "NO");
    397     printf("%sfragmentStoresAndAtomics: %s\n", indent, features.fragmentStoresAndAtomics ? "YES" : "NO");
    398     printf("%sshaderTessellationAndGeometryPointSize: %s\n", indent, features.shaderTessellationAndGeometryPointSize ? "YES" : "NO");
    399     printf("%sshaderImageGatherExtended: %s\n", indent, features.shaderImageGatherExtended ? "YES" : "NO");
    400     printf("%sshaderStorageImageExtendedFormats: %s\n", indent, features.shaderStorageImageExtendedFormats ? "YES" : "NO");
    401     printf("%sshaderStorageImageMultisample: %s\n", indent, features.shaderStorageImageMultisample ? "YES" : "NO");
    402     printf("%sshaderStorageImageReadWithoutFormat: %s\n", indent, features.shaderStorageImageReadWithoutFormat ? "YES" : "NO");
    403     printf("%sshaderStorageImageWriteWithoutFormat: %s\n", indent, features.shaderStorageImageWriteWithoutFormat ? "YES" : "NO");
    404     printf("%sshaderUniformBufferArrayDynamicIndexing: %s\n", indent, features.shaderUniformBufferArrayDynamicIndexing ? "YES" : "NO");
    405     printf("%sshaderSampledImageArrayDynamicIndexing: %s\n", indent, features.shaderSampledImageArrayDynamicIndexing ? "YES" : "NO");
    406     printf("%sshaderStorageBufferArrayDynamicIndexing: %s\n", indent, features.shaderStorageBufferArrayDynamicIndexing ? "YES" : "NO");
    407     printf("%sshaderStorageImageArrayDynamicIndexing: %s\n", indent, features.shaderStorageImageArrayDynamicIndexing ? "YES" : "NO");
    408     printf("%sshaderClipDistance: %s\n", indent, features.shaderClipDistance ? "YES" : "NO");
    409     printf("%sshaderCullDistance: %s\n", indent, features.shaderCullDistance ? "YES" : "NO");
    410     printf("%sshaderFloat64: %s\n", indent, features.shaderFloat64 ? "YES" : "NO");
    411     printf("%sshaderInt64: %s\n", indent, features.shaderInt64 ? "YES" : "NO");
    412     printf("%sshaderInt16: %s\n", indent, features.shaderInt16 ? "YES" : "NO");
    413     printf("%sshaderResourceResidency: %s\n", indent, features.shaderResourceResidency ? "YES" : "NO");
    414     printf("%sshaderResourceMinLod: %s\n", indent, features.shaderResourceMinLod ? "YES" : "NO");
    415     printf("%ssparseBinding: %s\n", indent, features.sparseBinding ? "YES" : "NO");
    416     printf("%ssparseResidencyBuffer: %s\n", indent, features.sparseResidencyBuffer ? "YES" : "NO");
    417     printf("%ssparseResidencyImage2D: %s\n", indent, features.sparseResidencyImage2D ? "YES" : "NO");
    418     printf("%ssparseResidencyImage3D: %s\n", indent, features.sparseResidencyImage3D ? "YES" : "NO");
    419     printf("%ssparseResidency2Samples: %s\n", indent, features.sparseResidency2Samples ? "YES" : "NO");
    420     printf("%ssparseResidency4Samples: %s\n", indent, features.sparseResidency4Samples ? "YES" : "NO");
    421     printf("%ssparseResidency8Samples: %s\n", indent, features.sparseResidency8Samples ? "YES" : "NO");
    422     printf("%ssparseResidency16Samples: %s\n", indent, features.sparseResidency16Samples ? "YES" : "NO");
    423     printf("%ssparseResidencyAliased: %s\n", indent, features.sparseResidencyAliased ? "YES" : "NO");
    424     printf("%svariableMultisampleRate: %s\n", indent, features.variableMultisampleRate ? "YES" : "NO");
    425     printf("%sinheritedQueries: %s\n", indent, features.inheritedQueries ? "YES" : "NO");
    426     // clang-format on
    427 }
    428 
    429 void PrintSupportedFeatures(const char* indent,
    430                             const VkPhysicalDeviceFeatures& features) {
    431     // clang-format off
    432     if (features.robustBufferAccess) printf("%srobustBufferAccess\n", indent);
    433     if (features.fullDrawIndexUint32) printf("%sfullDrawIndexUint32\n", indent);
    434     if (features.imageCubeArray) printf("%simageCubeArray\n", indent);
    435     if (features.independentBlend) printf("%sindependentBlend\n", indent);
    436     if (features.geometryShader) printf("%sgeometryShader\n", indent);
    437     if (features.tessellationShader) printf("%stessellationShader\n", indent);
    438     if (features.sampleRateShading) printf("%ssampleRateShading\n", indent);
    439     if (features.dualSrcBlend) printf("%sdualSrcBlend\n", indent);
    440     if (features.logicOp) printf("%slogicOp\n", indent);
    441     if (features.multiDrawIndirect) printf("%smultiDrawIndirect\n", indent);
    442     if (features.drawIndirectFirstInstance) printf("%sdrawIndirectFirstInstance\n", indent);
    443     if (features.depthClamp) printf("%sdepthClamp\n", indent);
    444     if (features.depthBiasClamp) printf("%sdepthBiasClamp\n", indent);
    445     if (features.fillModeNonSolid) printf("%sfillModeNonSolid\n", indent);
    446     if (features.depthBounds) printf("%sdepthBounds\n", indent);
    447     if (features.wideLines) printf("%swideLines\n", indent);
    448     if (features.largePoints) printf("%slargePoints\n", indent);
    449     if (features.alphaToOne) printf("%salphaToOne\n", indent);
    450     if (features.multiViewport) printf("%smultiViewport\n", indent);
    451     if (features.samplerAnisotropy) printf("%ssamplerAnisotropy\n", indent);
    452     if (features.textureCompressionETC2) printf("%stextureCompressionETC2\n", indent);
    453     if (features.textureCompressionASTC_LDR) printf("%stextureCompressionASTC_LDR\n", indent);
    454     if (features.textureCompressionBC) printf("%stextureCompressionBC\n", indent);
    455     if (features.occlusionQueryPrecise) printf("%socclusionQueryPrecise\n", indent);
    456     if (features.pipelineStatisticsQuery) printf("%spipelineStatisticsQuery\n", indent);
    457     if (features.vertexPipelineStoresAndAtomics) printf("%svertexPipelineStoresAndAtomics\n", indent);
    458     if (features.fragmentStoresAndAtomics) printf("%sfragmentStoresAndAtomics\n", indent);
    459     if (features.shaderTessellationAndGeometryPointSize) printf("%sshaderTessellationAndGeometryPointSize\n", indent);
    460     if (features.shaderImageGatherExtended) printf("%sshaderImageGatherExtended\n", indent);
    461     if (features.shaderStorageImageExtendedFormats) printf("%sshaderStorageImageExtendedFormats\n", indent);
    462     if (features.shaderStorageImageMultisample) printf("%sshaderStorageImageMultisample\n", indent);
    463     if (features.shaderStorageImageReadWithoutFormat) printf("%sshaderStorageImageReadWithoutFormat\n", indent);
    464     if (features.shaderStorageImageWriteWithoutFormat) printf("%sshaderStorageImageWriteWithoutFormat\n", indent);
    465     if (features.shaderUniformBufferArrayDynamicIndexing) printf("%sshaderUniformBufferArrayDynamicIndexing\n", indent);
    466     if (features.shaderSampledImageArrayDynamicIndexing) printf("%sshaderSampledImageArrayDynamicIndexing\n", indent);
    467     if (features.shaderStorageBufferArrayDynamicIndexing) printf("%sshaderStorageBufferArrayDynamicIndexing\n", indent);
    468     if (features.shaderStorageImageArrayDynamicIndexing) printf("%sshaderStorageImageArrayDynamicIndexing\n", indent);
    469     if (features.shaderClipDistance) printf("%sshaderClipDistance\n", indent);
    470     if (features.shaderCullDistance) printf("%sshaderCullDistance\n", indent);
    471     if (features.shaderFloat64) printf("%sshaderFloat64\n", indent);
    472     if (features.shaderInt64) printf("%sshaderInt64\n", indent);
    473     if (features.shaderInt16) printf("%sshaderInt16\n", indent);
    474     if (features.shaderResourceResidency) printf("%sshaderResourceResidency\n", indent);
    475     if (features.shaderResourceMinLod) printf("%sshaderResourceMinLod\n", indent);
    476     if (features.sparseBinding) printf("%ssparseBinding\n", indent);
    477     if (features.sparseResidencyBuffer) printf("%ssparseResidencyBuffer\n", indent);
    478     if (features.sparseResidencyImage2D) printf("%ssparseResidencyImage2D\n", indent);
    479     if (features.sparseResidencyImage3D) printf("%ssparseResidencyImage3D\n", indent);
    480     if (features.sparseResidency2Samples) printf("%ssparseResidency2Samples\n", indent);
    481     if (features.sparseResidency4Samples) printf("%ssparseResidency4Samples\n", indent);
    482     if (features.sparseResidency8Samples) printf("%ssparseResidency8Samples\n", indent);
    483     if (features.sparseResidency16Samples) printf("%ssparseResidency16Samples\n", indent);
    484     if (features.sparseResidencyAliased) printf("%ssparseResidencyAliased\n", indent);
    485     if (features.variableMultisampleRate) printf("%svariableMultisampleRate\n", indent);
    486     if (features.inheritedQueries) printf("%sinheritedQueries\n", indent);
    487     // clang-format on
    488 }
    489 
    490 void PrintGpuInfo(const GpuInfo& info, const Options& options, size_t indent) {
    491     VkResult result;
    492     std::ostringstream strbuf;
    493 
    494     printf("%s\"%s\" (%s) %u.%u.%u/%#x [%04x:%04x]\n", Indent(indent),
    495            info.properties.deviceName,
    496            VkPhysicalDeviceTypeStr(info.properties.deviceType),
    497            VK_VERSION_MAJOR(info.properties.apiVersion),
    498            VK_VERSION_MINOR(info.properties.apiVersion),
    499            VK_VERSION_PATCH(info.properties.apiVersion),
    500            info.properties.driverVersion, info.properties.vendorID,
    501            info.properties.deviceID);
    502 
    503     for (uint32_t heap = 0; heap < info.memory.memoryHeapCount; heap++) {
    504         if ((info.memory.memoryHeaps[heap].flags &
    505              VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0)
    506             strbuf << "DEVICE_LOCAL";
    507         printf("%sHeap %u: %" PRIu64 " MiB (0x%" PRIx64 " B) %s\n",
    508                Indent(indent + 1), heap,
    509                info.memory.memoryHeaps[heap].size / 0x100000,
    510                info.memory.memoryHeaps[heap].size, strbuf.str().c_str());
    511         strbuf.str(std::string());
    512 
    513         for (uint32_t type = 0; type < info.memory.memoryTypeCount; type++) {
    514             if (info.memory.memoryTypes[type].heapIndex != heap)
    515                 continue;
    516             VkMemoryPropertyFlags flags =
    517                 info.memory.memoryTypes[type].propertyFlags;
    518             if ((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0)
    519                 strbuf << " DEVICE_LOCAL";
    520             if ((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
    521                 strbuf << " HOST_VISIBLE";
    522             if ((flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0)
    523                 strbuf << " COHERENT";
    524             if ((flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) != 0)
    525                 strbuf << " CACHED";
    526             if ((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0)
    527                 strbuf << " LAZILY_ALLOCATED";
    528             printf("%sType %u:%s\n", Indent(indent + 2), type,
    529                    strbuf.str().c_str());
    530             strbuf.str(std::string());
    531         }
    532     }
    533 
    534     for (uint32_t family = 0; family < info.queue_families.size(); family++) {
    535         const VkQueueFamilyProperties& qprops = info.queue_families[family];
    536         VkQueueFlags flags = qprops.queueFlags;
    537         char flags_str[5];
    538         flags_str[0] = (flags & VK_QUEUE_GRAPHICS_BIT) ? 'G' : '_';
    539         flags_str[1] = (flags & VK_QUEUE_COMPUTE_BIT) ? 'C' : '_';
    540         flags_str[2] = (flags & VK_QUEUE_TRANSFER_BIT) ? 'T' : '_';
    541         flags_str[3] = (flags & VK_QUEUE_SPARSE_BINDING_BIT) ? 'S' : '_';
    542         flags_str[4] = '\0';
    543         printf(
    544             "%sQueue Family %u: %ux %s\n"
    545             "%stimestampValidBits: %ub\n"
    546             "%sminImageTransferGranularity: (%u,%u,%u)\n",
    547             Indent(indent + 1), family, qprops.queueCount, flags_str,
    548             Indent(indent + 2), qprops.timestampValidBits, Indent(indent + 2),
    549             qprops.minImageTransferGranularity.width,
    550             qprops.minImageTransferGranularity.height,
    551             qprops.minImageTransferGranularity.depth);
    552     }
    553 
    554     printf("%sFeatures:\n", Indent(indent + 1));
    555     if (options.unsupported_features) {
    556         PrintAllFeatures(Indent(indent + 2), info.features);
    557     } else {
    558         PrintSupportedFeatures(Indent(indent + 2), info.features);
    559     }
    560 
    561     printf("%sExtensions [%zu]:\n", Indent(indent + 1), info.extensions.size());
    562     if (!info.extensions.empty())
    563         PrintExtensions(info.extensions, options, indent + 2);
    564     printf("%sLayers [%zu]:\n", Indent(indent + 1), info.layers.size());
    565     if (!info.layers.empty())
    566         PrintLayers(info.layers, info.layer_extensions, options, indent + 2);
    567 }
    568 
    569 void PrintInfo(const VulkanInfo& info, const Options& options) {
    570     std::ostringstream strbuf;
    571     size_t indent = 0;
    572 
    573     printf("%sInstance Extensions [%zu]:\n", Indent(indent),
    574            info.extensions.size());
    575     PrintExtensions(info.extensions, options, indent + 1);
    576     printf("%sInstance Layers [%zu]:\n", Indent(indent), info.layers.size());
    577     if (!info.layers.empty())
    578         PrintLayers(info.layers, info.layer_extensions, options, indent + 1);
    579 
    580     printf("%sPhysicalDevices [%zu]:\n", Indent(indent), info.gpus.size());
    581     for (const auto& gpu : info.gpus)
    582         PrintGpuInfo(gpu, options, indent + 1);
    583 }
    584 
    585 const char kUsageString[] =
    586     "usage: vkinfo [options]\n"
    587     "  -v                       enable all the following verbose options\n"
    588     "    -layer_description     print layer description strings\n"
    589     "    -layer_extensions      print extensions supported by each layer\n"
    590     "    -unsupported_features  print all physical device features\n"
    591     "  -validate                enable validation layers if present\n"
    592     "  -debug_pause             pause at start until resumed via debugger\n";
    593 
    594 }  // namespace
    595 
    596 // ----------------------------------------------------------------------------
    597 
    598 int main(int argc, char const* argv[]) {
    599     static volatile bool startup_pause = false;
    600     Options options = {
    601         .layer_description = false, .layer_extensions = false,
    602         .unsupported_features = false,
    603         .validate = false,
    604     };
    605     for (int argi = 1; argi < argc; argi++) {
    606         if (strcmp(argv[argi], "-h") == 0) {
    607             fputs(kUsageString, stdout);
    608             return 0;
    609         }
    610         if (strcmp(argv[argi], "-v") == 0) {
    611             options.layer_description = true;
    612             options.layer_extensions = true;
    613             options.unsupported_features = true;
    614         } else if (strcmp(argv[argi], "-layer_description") == 0) {
    615             options.layer_description = true;
    616         } else if (strcmp(argv[argi], "-layer_extensions") == 0) {
    617             options.layer_extensions = true;
    618         } else if (strcmp(argv[argi], "-unsupported_features") == 0) {
    619             options.unsupported_features = true;
    620         } else if (strcmp(argv[argi], "-validate") == 0) {
    621             options.validate = true;
    622         } else if (strcmp(argv[argi], "-debug_pause") == 0) {
    623             startup_pause = true;
    624         }
    625     }
    626 
    627     while (startup_pause) {
    628         sleep(0);
    629     }
    630 
    631     VulkanInfo info;
    632     GatherInfo(&info, options);
    633     PrintInfo(info, options);
    634     return 0;
    635 }
    636