blob: 583e6079fed99ec3c503531857485f5e040a9f08 [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 Hall73ab0ac2015-08-25 15:09:15 +010017#include <inttypes.h>
18#include <sstream>
Jesse Hall04f4f472015-08-16 19:51:04 -070019#include <stdlib.h>
20#include <vector>
21
22#define VK_PROTOTYPES
23#include <vulkan/vulkan.h>
24
25#define LOG_TAG "vkinfo"
26#include <log/log.h>
27
28namespace {
29
30[[noreturn]] void die(const char* proc, VkResult result) {
31 const char* result_str;
32 switch (result) {
33 // clang-format off
34 case VK_SUCCESS: result_str = "VK_SUCCESS"; break;
35 case VK_UNSUPPORTED: result_str = "VK_UNSUPPORTED"; break;
36 case VK_NOT_READY: result_str = "VK_NOT_READY"; break;
37 case VK_TIMEOUT: result_str = "VK_TIMEOUT"; break;
38 case VK_EVENT_SET: result_str = "VK_EVENT_SET"; break;
39 case VK_EVENT_RESET: result_str = "VK_EVENT_RESET"; break;
40 case VK_INCOMPLETE: result_str = "VK_INCOMPLETE"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070041 case VK_ERROR_OUT_OF_HOST_MEMORY: result_str = "VK_ERROR_OUT_OF_HOST_MEMORY"; break;
42 case VK_ERROR_OUT_OF_DEVICE_MEMORY: result_str = "VK_ERROR_OUT_OF_DEVICE_MEMORY"; break;
Jesse Hall5ae3abb2015-10-08 14:00:22 -070043 case VK_ERROR_INITIALIZATION_FAILED: result_str = "VK_ERROR_INITIALIZATION_FAILED"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070044 case VK_ERROR_DEVICE_LOST: result_str = "VK_ERROR_DEVICE_LOST"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070045 case VK_ERROR_MEMORY_MAP_FAILED: result_str = "VK_ERROR_MEMORY_MAP_FAILED"; break;
Jesse Hall5ae3abb2015-10-08 14:00:22 -070046 case VK_ERROR_LAYER_NOT_PRESENT: result_str = "VK_ERROR_LAYER_NOT_PRESENT"; break;
47 case VK_ERROR_EXTENSION_NOT_PRESENT: result_str = "VK_ERROR_EXTENSION_NOT_PRESENT"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070048 case VK_ERROR_INCOMPATIBLE_DRIVER: result_str = "VK_ERROR_INCOMPATIBLE_DRIVER"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070049 default: result_str = "<unknown VkResult>"; break;
50 // clang-format on
51 }
52 fprintf(stderr, "%s failed: %s (%d)\n", proc, result_str, result);
53 exit(1);
54}
55
56const char* VkPhysicalDeviceTypeStr(VkPhysicalDeviceType type) {
57 switch (type) {
58 case VK_PHYSICAL_DEVICE_TYPE_OTHER:
59 return "OTHER";
60 case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
61 return "INTEGRATED_GPU";
62 case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
63 return "DISCRETE_GPU";
64 case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
65 return "VIRTUAL_GPU";
66 case VK_PHYSICAL_DEVICE_TYPE_CPU:
67 return "CPU";
68 default:
69 return "<UNKNOWN>";
70 }
71}
72
Jesse Hall5ae3abb2015-10-08 14:00:22 -070073const char* VkQueueFlagBitStr(VkQueueFlagBits bit) {
74 switch (bit) {
75 case VK_QUEUE_GRAPHICS_BIT:
76 return "GRAPHICS";
77 case VK_QUEUE_COMPUTE_BIT:
78 return "COMPUTE";
79 case VK_QUEUE_DMA_BIT:
80 return "DMA";
81 case VK_QUEUE_SPARSE_MEMMGR_BIT:
82 return "SPARSE";
83 case VK_QUEUE_EXTENDED_BIT:
84 return "EXT";
85 }
86}
87
Jesse Hall04f4f472015-08-16 19:51:04 -070088void DumpPhysicalDevice(uint32_t idx, VkPhysicalDevice pdev) {
89 VkResult result;
Jesse Hall73ab0ac2015-08-25 15:09:15 +010090 std::ostringstream strbuf;
Jesse Hall04f4f472015-08-16 19:51:04 -070091
92 VkPhysicalDeviceProperties props;
93 result = vkGetPhysicalDeviceProperties(pdev, &props);
94 if (result != VK_SUCCESS)
95 die("vkGetPhysicalDeviceProperties", result);
96 printf(" %u: \"%s\" (%s) %u.%u.%u/%#x [%04x:%04x]\n", idx,
97 props.deviceName, VkPhysicalDeviceTypeStr(props.deviceType),
98 (props.apiVersion >> 22) & 0x3FF, (props.apiVersion >> 12) & 0x3FF,
99 (props.apiVersion >> 0) & 0xFFF, props.driverVersion, props.vendorId,
100 props.deviceId);
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100101
102 VkPhysicalDeviceMemoryProperties mem_props;
103 result = vkGetPhysicalDeviceMemoryProperties(pdev, &mem_props);
104 if (result != VK_SUCCESS)
105 die("vkGetPhysicalDeviceMemoryProperties", result);
106 for (uint32_t heap = 0; heap < mem_props.memoryHeapCount; heap++) {
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700107 if ((mem_props.memoryHeaps[heap].flags &
108 VK_MEMORY_HEAP_HOST_LOCAL_BIT) != 0)
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100109 strbuf << "HOST_LOCAL";
110 printf(" Heap %u: 0x%" PRIx64 " %s\n", heap,
111 mem_props.memoryHeaps[heap].size, strbuf.str().c_str());
112 strbuf.str(std::string());
113
114 for (uint32_t type = 0; type < mem_props.memoryTypeCount; type++) {
115 if (mem_props.memoryTypes[type].heapIndex != heap)
116 continue;
117 VkMemoryPropertyFlags flags =
118 mem_props.memoryTypes[type].propertyFlags;
119 if (flags == VK_MEMORY_PROPERTY_DEVICE_ONLY)
120 strbuf << "DEVICE_ONLY";
121 if ((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
122 strbuf << "HOST_VISIBLE";
123 if ((flags & VK_MEMORY_PROPERTY_HOST_NON_COHERENT_BIT) != 0)
124 strbuf << " NON_COHERENT";
125 if ((flags & VK_MEMORY_PROPERTY_HOST_UNCACHED_BIT) != 0)
126 strbuf << " UNCACHED";
127 if ((flags & VK_MEMORY_PROPERTY_HOST_WRITE_COMBINED_BIT) != 0)
128 strbuf << " WRITE_COMBINED";
129 if ((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0)
130 strbuf << " LAZILY_ALLOCATED";
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700131 printf(" Type %u: %s\n", type, strbuf.str().c_str());
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100132 strbuf.str(std::string());
133 }
134 }
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700135
136 uint32_t num_queue_families;
137 result = vkGetPhysicalDeviceQueueFamilyProperties(pdev, &num_queue_families,
138 nullptr);
139 if (result != VK_SUCCESS)
140 die("vkGetPhysicalDeviceQueueFamilyProperties (count)", result);
141 std::vector<VkQueueFamilyProperties> queue_family_properties(
142 num_queue_families);
143 result = vkGetPhysicalDeviceQueueFamilyProperties(
144 pdev, &num_queue_families, queue_family_properties.data());
145 if (result != VK_SUCCESS)
146 die("vkGetPhysicalDeviceQueueFamilyProperties (values)", result);
147 for (uint32_t family = 0; family < num_queue_families; family++) {
148 const VkQueueFamilyProperties& qprops = queue_family_properties[family];
149 const char* sep = "";
150 int bit, queue_flags = static_cast<int>(qprops.queueFlags);
151 while ((bit = __builtin_ffs(queue_flags)) != 0) {
152 VkQueueFlagBits flag = VkQueueFlagBits(1 << (bit - 1));
153 strbuf << sep << VkQueueFlagBitStr(flag);
154 queue_flags &= ~flag;
155 sep = "+";
156 }
157 printf(" Queue Family %u: %2ux %s timestamps:%s\n", family,
158 qprops.queueCount, strbuf.str().c_str(),
159 qprops.supportsTimestamps ? "YES" : "NO");
160 strbuf.str(std::string());
161 }
Jesse Hall04f4f472015-08-16 19:51:04 -0700162}
163
164} // namespace
165
166int main(int /*argc*/, char const* /*argv*/ []) {
167 VkResult result;
168
169 VkInstance instance;
170 const VkInstanceCreateInfo create_info = {
171 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
172 .pNext = nullptr,
173 .pAppInfo = nullptr,
174 .pAllocCb = nullptr,
175 .layerCount = 0,
176 .ppEnabledLayerNames = nullptr,
177 .extensionCount = 0,
178 .ppEnabledExtensionNames = nullptr,
179 };
180 result = vkCreateInstance(&create_info, &instance);
181 if (result != VK_SUCCESS)
182 die("vkCreateInstance", result);
183
184 uint32_t num_physical_devices;
185 result =
186 vkEnumeratePhysicalDevices(instance, &num_physical_devices, nullptr);
187 if (result != VK_SUCCESS)
188 die("vkEnumeratePhysicalDevices (count)", result);
189 std::vector<VkPhysicalDevice> physical_devices(num_physical_devices,
190 VK_NULL_HANDLE);
191 result = vkEnumeratePhysicalDevices(instance, &num_physical_devices,
192 physical_devices.data());
193 if (result != VK_SUCCESS)
194 die("vkEnumeratePhysicalDevices (data)", result);
195 if (num_physical_devices != physical_devices.size()) {
196 fprintf(stderr,
197 "number of physical devices decreased from %zu to %u!\n",
198 physical_devices.size(), num_physical_devices);
199 physical_devices.resize(num_physical_devices);
200 }
201 printf("PhysicalDevices:\n");
202 for (uint32_t i = 0; i < physical_devices.size(); i++)
203 DumpPhysicalDevice(i, physical_devices[i]);
204
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700205 vkDestroyInstance(instance);
Jesse Hall04f4f472015-08-16 19:51:04 -0700206
207 return 0;
208}