blob: 918df471f622f219817e3f06a83eb8ed0c1a8abe [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;
Jesse Hall04f4f472015-08-16 19:51:04 -070035 case VK_NOT_READY: result_str = "VK_NOT_READY"; break;
36 case VK_TIMEOUT: result_str = "VK_TIMEOUT"; break;
37 case VK_EVENT_SET: result_str = "VK_EVENT_SET"; break;
38 case VK_EVENT_RESET: result_str = "VK_EVENT_RESET"; break;
39 case VK_INCOMPLETE: result_str = "VK_INCOMPLETE"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070040 case VK_ERROR_OUT_OF_HOST_MEMORY: result_str = "VK_ERROR_OUT_OF_HOST_MEMORY"; break;
41 case VK_ERROR_OUT_OF_DEVICE_MEMORY: result_str = "VK_ERROR_OUT_OF_DEVICE_MEMORY"; break;
Jesse Hall5ae3abb2015-10-08 14:00:22 -070042 case VK_ERROR_INITIALIZATION_FAILED: result_str = "VK_ERROR_INITIALIZATION_FAILED"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070043 case VK_ERROR_DEVICE_LOST: result_str = "VK_ERROR_DEVICE_LOST"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070044 case VK_ERROR_MEMORY_MAP_FAILED: result_str = "VK_ERROR_MEMORY_MAP_FAILED"; break;
Jesse Hall5ae3abb2015-10-08 14:00:22 -070045 case VK_ERROR_LAYER_NOT_PRESENT: result_str = "VK_ERROR_LAYER_NOT_PRESENT"; break;
46 case VK_ERROR_EXTENSION_NOT_PRESENT: result_str = "VK_ERROR_EXTENSION_NOT_PRESENT"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070047 case VK_ERROR_INCOMPATIBLE_DRIVER: result_str = "VK_ERROR_INCOMPATIBLE_DRIVER"; break;
Jesse Hall04f4f472015-08-16 19:51:04 -070048 default: result_str = "<unknown VkResult>"; break;
49 // clang-format on
50 }
51 fprintf(stderr, "%s failed: %s (%d)\n", proc, result_str, result);
52 exit(1);
53}
54
55const char* VkPhysicalDeviceTypeStr(VkPhysicalDeviceType type) {
56 switch (type) {
57 case VK_PHYSICAL_DEVICE_TYPE_OTHER:
58 return "OTHER";
59 case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
60 return "INTEGRATED_GPU";
61 case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
62 return "DISCRETE_GPU";
63 case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
64 return "VIRTUAL_GPU";
65 case VK_PHYSICAL_DEVICE_TYPE_CPU:
66 return "CPU";
67 default:
68 return "<UNKNOWN>";
69 }
70}
71
Jesse Hall5ae3abb2015-10-08 14:00:22 -070072const char* VkQueueFlagBitStr(VkQueueFlagBits bit) {
73 switch (bit) {
74 case VK_QUEUE_GRAPHICS_BIT:
75 return "GRAPHICS";
76 case VK_QUEUE_COMPUTE_BIT:
77 return "COMPUTE";
78 case VK_QUEUE_DMA_BIT:
79 return "DMA";
80 case VK_QUEUE_SPARSE_MEMMGR_BIT:
81 return "SPARSE";
82 case VK_QUEUE_EXTENDED_BIT:
83 return "EXT";
84 }
85}
86
Jesse Hall04f4f472015-08-16 19:51:04 -070087void DumpPhysicalDevice(uint32_t idx, VkPhysicalDevice pdev) {
88 VkResult result;
Jesse Hall73ab0ac2015-08-25 15:09:15 +010089 std::ostringstream strbuf;
Jesse Hall04f4f472015-08-16 19:51:04 -070090
91 VkPhysicalDeviceProperties props;
Jesse Hall606a54e2015-11-19 22:17:28 -080092 vkGetPhysicalDeviceProperties(pdev, &props);
Jesse Hall04f4f472015-08-16 19:51:04 -070093 printf(" %u: \"%s\" (%s) %u.%u.%u/%#x [%04x:%04x]\n", idx,
94 props.deviceName, VkPhysicalDeviceTypeStr(props.deviceType),
95 (props.apiVersion >> 22) & 0x3FF, (props.apiVersion >> 12) & 0x3FF,
96 (props.apiVersion >> 0) & 0xFFF, props.driverVersion, props.vendorId,
97 props.deviceId);
Jesse Hall73ab0ac2015-08-25 15:09:15 +010098
99 VkPhysicalDeviceMemoryProperties mem_props;
Jesse Hall606a54e2015-11-19 22:17:28 -0800100 vkGetPhysicalDeviceMemoryProperties(pdev, &mem_props);
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100101 for (uint32_t heap = 0; heap < mem_props.memoryHeapCount; heap++) {
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700102 if ((mem_props.memoryHeaps[heap].flags &
103 VK_MEMORY_HEAP_HOST_LOCAL_BIT) != 0)
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100104 strbuf << "HOST_LOCAL";
105 printf(" Heap %u: 0x%" PRIx64 " %s\n", heap,
106 mem_props.memoryHeaps[heap].size, strbuf.str().c_str());
107 strbuf.str(std::string());
108
109 for (uint32_t type = 0; type < mem_props.memoryTypeCount; type++) {
110 if (mem_props.memoryTypes[type].heapIndex != heap)
111 continue;
112 VkMemoryPropertyFlags flags =
113 mem_props.memoryTypes[type].propertyFlags;
114 if (flags == VK_MEMORY_PROPERTY_DEVICE_ONLY)
115 strbuf << "DEVICE_ONLY";
116 if ((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0)
117 strbuf << "HOST_VISIBLE";
118 if ((flags & VK_MEMORY_PROPERTY_HOST_NON_COHERENT_BIT) != 0)
119 strbuf << " NON_COHERENT";
120 if ((flags & VK_MEMORY_PROPERTY_HOST_UNCACHED_BIT) != 0)
121 strbuf << " UNCACHED";
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100122 if ((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0)
123 strbuf << " LAZILY_ALLOCATED";
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700124 printf(" Type %u: %s\n", type, strbuf.str().c_str());
Jesse Hall73ab0ac2015-08-25 15:09:15 +0100125 strbuf.str(std::string());
126 }
127 }
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700128
129 uint32_t num_queue_families;
Jesse Hall606a54e2015-11-19 22:17:28 -0800130 vkGetPhysicalDeviceQueueFamilyProperties(pdev, &num_queue_families,
131 nullptr);
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700132 std::vector<VkQueueFamilyProperties> queue_family_properties(
133 num_queue_families);
Jesse Hall606a54e2015-11-19 22:17:28 -0800134 vkGetPhysicalDeviceQueueFamilyProperties(pdev, &num_queue_families,
135 queue_family_properties.data());
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700136 for (uint32_t family = 0; family < num_queue_families; family++) {
137 const VkQueueFamilyProperties& qprops = queue_family_properties[family];
138 const char* sep = "";
139 int bit, queue_flags = static_cast<int>(qprops.queueFlags);
140 while ((bit = __builtin_ffs(queue_flags)) != 0) {
141 VkQueueFlagBits flag = VkQueueFlagBits(1 << (bit - 1));
142 strbuf << sep << VkQueueFlagBitStr(flag);
143 queue_flags &= ~flag;
144 sep = "+";
145 }
Jesse Hallacfa5342015-11-19 21:51:33 -0800146 printf(" Queue Family %u: %2ux %s timestamps:%ub\n", family,
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700147 qprops.queueCount, strbuf.str().c_str(),
Jesse Hallacfa5342015-11-19 21:51:33 -0800148 qprops.timestampValidBits);
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700149 strbuf.str(std::string());
150 }
Jesse Hall04f4f472015-08-16 19:51:04 -0700151}
152
153} // namespace
154
155int main(int /*argc*/, char const* /*argv*/ []) {
156 VkResult result;
157
158 VkInstance instance;
159 const VkInstanceCreateInfo create_info = {
160 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
161 .pNext = nullptr,
162 .pAppInfo = nullptr,
163 .pAllocCb = nullptr,
164 .layerCount = 0,
165 .ppEnabledLayerNames = nullptr,
166 .extensionCount = 0,
167 .ppEnabledExtensionNames = nullptr,
168 };
169 result = vkCreateInstance(&create_info, &instance);
170 if (result != VK_SUCCESS)
171 die("vkCreateInstance", result);
172
173 uint32_t num_physical_devices;
174 result =
175 vkEnumeratePhysicalDevices(instance, &num_physical_devices, nullptr);
176 if (result != VK_SUCCESS)
177 die("vkEnumeratePhysicalDevices (count)", result);
178 std::vector<VkPhysicalDevice> physical_devices(num_physical_devices,
179 VK_NULL_HANDLE);
180 result = vkEnumeratePhysicalDevices(instance, &num_physical_devices,
181 physical_devices.data());
182 if (result != VK_SUCCESS)
183 die("vkEnumeratePhysicalDevices (data)", result);
184 if (num_physical_devices != physical_devices.size()) {
185 fprintf(stderr,
186 "number of physical devices decreased from %zu to %u!\n",
187 physical_devices.size(), num_physical_devices);
188 physical_devices.resize(num_physical_devices);
189 }
190 printf("PhysicalDevices:\n");
191 for (uint32_t i = 0; i < physical_devices.size(); i++)
192 DumpPhysicalDevice(i, physical_devices[i]);
193
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700194 vkDestroyInstance(instance);
Jesse Hall04f4f472015-08-16 19:51:04 -0700195
196 return 0;
197}