Jesse Hall | 73ab0ac | 2015-08-25 15:09:15 +0100 | [diff] [blame] | 1 | #include <inttypes.h> |
| 2 | #include <sstream> |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 3 | #include <stdlib.h> |
| 4 | #include <vector> |
| 5 | |
| 6 | #define VK_PROTOTYPES |
| 7 | #include <vulkan/vulkan.h> |
| 8 | |
| 9 | #define LOG_TAG "vkinfo" |
| 10 | #include <log/log.h> |
| 11 | |
| 12 | namespace { |
| 13 | |
| 14 | [[noreturn]] void die(const char* proc, VkResult result) { |
| 15 | const char* result_str; |
| 16 | switch (result) { |
| 17 | // clang-format off |
| 18 | case VK_SUCCESS: result_str = "VK_SUCCESS"; break; |
| 19 | case VK_UNSUPPORTED: result_str = "VK_UNSUPPORTED"; break; |
| 20 | case VK_NOT_READY: result_str = "VK_NOT_READY"; break; |
| 21 | case VK_TIMEOUT: result_str = "VK_TIMEOUT"; break; |
| 22 | case VK_EVENT_SET: result_str = "VK_EVENT_SET"; break; |
| 23 | case VK_EVENT_RESET: result_str = "VK_EVENT_RESET"; break; |
| 24 | case VK_INCOMPLETE: result_str = "VK_INCOMPLETE"; break; |
| 25 | case VK_ERROR_UNKNOWN: result_str = "VK_ERROR_UNKNOWN"; break; |
| 26 | case VK_ERROR_UNAVAILABLE: result_str = "VK_ERROR_UNAVAILABLE"; break; |
| 27 | case VK_ERROR_INITIALIZATION_FAILED: result_str = "VK_ERROR_INITIALIZATION_FAILED"; break; |
| 28 | case VK_ERROR_OUT_OF_HOST_MEMORY: result_str = "VK_ERROR_OUT_OF_HOST_MEMORY"; break; |
| 29 | case VK_ERROR_OUT_OF_DEVICE_MEMORY: result_str = "VK_ERROR_OUT_OF_DEVICE_MEMORY"; break; |
| 30 | case VK_ERROR_DEVICE_ALREADY_CREATED: result_str = "VK_ERROR_DEVICE_ALREADY_CREATED"; break; |
| 31 | case VK_ERROR_DEVICE_LOST: result_str = "VK_ERROR_DEVICE_LOST"; break; |
| 32 | case VK_ERROR_INVALID_POINTER: result_str = "VK_ERROR_INVALID_POINTER"; break; |
| 33 | case VK_ERROR_INVALID_VALUE: result_str = "VK_ERROR_INVALID_VALUE"; break; |
| 34 | case VK_ERROR_INVALID_HANDLE: result_str = "VK_ERROR_INVALID_HANDLE"; break; |
| 35 | case VK_ERROR_INVALID_ORDINAL: result_str = "VK_ERROR_INVALID_ORDINAL"; break; |
| 36 | case VK_ERROR_INVALID_MEMORY_SIZE: result_str = "VK_ERROR_INVALID_MEMORY_SIZE"; break; |
| 37 | case VK_ERROR_INVALID_EXTENSION: result_str = "VK_ERROR_INVALID_EXTENSION"; break; |
| 38 | case VK_ERROR_INVALID_FLAGS: result_str = "VK_ERROR_INVALID_FLAGS"; break; |
| 39 | case VK_ERROR_INVALID_ALIGNMENT: result_str = "VK_ERROR_INVALID_ALIGNMENT"; break; |
| 40 | case VK_ERROR_INVALID_FORMAT: result_str = "VK_ERROR_INVALID_FORMAT"; break; |
| 41 | case VK_ERROR_INVALID_IMAGE: result_str = "VK_ERROR_INVALID_IMAGE"; break; |
| 42 | case VK_ERROR_INVALID_DESCRIPTOR_SET_DATA: result_str = "VK_ERROR_INVALID_DESCRIPTOR_SET_DATA"; break; |
| 43 | case VK_ERROR_INVALID_QUEUE_TYPE: result_str = "VK_ERROR_INVALID_QUEUE_TYPE"; break; |
| 44 | case VK_ERROR_UNSUPPORTED_SHADER_IL_VERSION: result_str = "VK_ERROR_UNSUPPORTED_SHADER_IL_VERSION"; break; |
| 45 | case VK_ERROR_BAD_SHADER_CODE: result_str = "VK_ERROR_BAD_SHADER_CODE"; break; |
| 46 | case VK_ERROR_BAD_PIPELINE_DATA: result_str = "VK_ERROR_BAD_PIPELINE_DATA"; break; |
| 47 | case VK_ERROR_NOT_MAPPABLE: result_str = "VK_ERROR_NOT_MAPPABLE"; break; |
| 48 | case VK_ERROR_MEMORY_MAP_FAILED: result_str = "VK_ERROR_MEMORY_MAP_FAILED"; break; |
| 49 | case VK_ERROR_MEMORY_UNMAP_FAILED: result_str = "VK_ERROR_MEMORY_UNMAP_FAILED"; break; |
| 50 | case VK_ERROR_INCOMPATIBLE_DEVICE: result_str = "VK_ERROR_INCOMPATIBLE_DEVICE"; break; |
| 51 | case VK_ERROR_INCOMPATIBLE_DRIVER: result_str = "VK_ERROR_INCOMPATIBLE_DRIVER"; break; |
| 52 | case VK_ERROR_INCOMPLETE_COMMAND_BUFFER: result_str = "VK_ERROR_INCOMPLETE_COMMAND_BUFFER"; break; |
| 53 | case VK_ERROR_BUILDING_COMMAND_BUFFER: result_str = "VK_ERROR_BUILDING_COMMAND_BUFFER"; break; |
| 54 | case VK_ERROR_MEMORY_NOT_BOUND: result_str = "VK_ERROR_MEMORY_NOT_BOUND"; break; |
| 55 | case VK_ERROR_INCOMPATIBLE_QUEUE: result_str = "VK_ERROR_INCOMPATIBLE_QUEUE"; break; |
| 56 | case VK_ERROR_INVALID_LAYER: result_str = "VK_ERROR_INVALID_LAYER"; break; |
| 57 | default: result_str = "<unknown VkResult>"; break; |
| 58 | // clang-format on |
| 59 | } |
| 60 | fprintf(stderr, "%s failed: %s (%d)\n", proc, result_str, result); |
| 61 | exit(1); |
| 62 | } |
| 63 | |
| 64 | const char* VkPhysicalDeviceTypeStr(VkPhysicalDeviceType type) { |
| 65 | switch (type) { |
| 66 | case VK_PHYSICAL_DEVICE_TYPE_OTHER: |
| 67 | return "OTHER"; |
| 68 | case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: |
| 69 | return "INTEGRATED_GPU"; |
| 70 | case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: |
| 71 | return "DISCRETE_GPU"; |
| 72 | case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: |
| 73 | return "VIRTUAL_GPU"; |
| 74 | case VK_PHYSICAL_DEVICE_TYPE_CPU: |
| 75 | return "CPU"; |
| 76 | default: |
| 77 | return "<UNKNOWN>"; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | void DumpPhysicalDevice(uint32_t idx, VkPhysicalDevice pdev) { |
| 82 | VkResult result; |
Jesse Hall | 73ab0ac | 2015-08-25 15:09:15 +0100 | [diff] [blame] | 83 | std::ostringstream strbuf; |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 84 | |
| 85 | VkPhysicalDeviceProperties props; |
| 86 | result = vkGetPhysicalDeviceProperties(pdev, &props); |
| 87 | if (result != VK_SUCCESS) |
| 88 | die("vkGetPhysicalDeviceProperties", result); |
| 89 | printf(" %u: \"%s\" (%s) %u.%u.%u/%#x [%04x:%04x]\n", idx, |
| 90 | props.deviceName, VkPhysicalDeviceTypeStr(props.deviceType), |
| 91 | (props.apiVersion >> 22) & 0x3FF, (props.apiVersion >> 12) & 0x3FF, |
| 92 | (props.apiVersion >> 0) & 0xFFF, props.driverVersion, props.vendorId, |
| 93 | props.deviceId); |
Jesse Hall | 73ab0ac | 2015-08-25 15:09:15 +0100 | [diff] [blame] | 94 | |
| 95 | VkPhysicalDeviceMemoryProperties mem_props; |
| 96 | result = vkGetPhysicalDeviceMemoryProperties(pdev, &mem_props); |
| 97 | if (result != VK_SUCCESS) |
| 98 | die("vkGetPhysicalDeviceMemoryProperties", result); |
| 99 | for (uint32_t heap = 0; heap < mem_props.memoryHeapCount; heap++) { |
| 100 | if ((mem_props.memoryHeaps[heap].flags & VK_MEMORY_HEAP_HOST_LOCAL) != |
| 101 | 0) |
| 102 | strbuf << "HOST_LOCAL"; |
| 103 | printf(" Heap %u: 0x%" PRIx64 " %s\n", heap, |
| 104 | mem_props.memoryHeaps[heap].size, strbuf.str().c_str()); |
| 105 | strbuf.str(std::string()); |
| 106 | |
| 107 | for (uint32_t type = 0; type < mem_props.memoryTypeCount; type++) { |
| 108 | if (mem_props.memoryTypes[type].heapIndex != heap) |
| 109 | continue; |
| 110 | VkMemoryPropertyFlags flags = |
| 111 | mem_props.memoryTypes[type].propertyFlags; |
| 112 | if (flags == VK_MEMORY_PROPERTY_DEVICE_ONLY) |
| 113 | strbuf << "DEVICE_ONLY"; |
| 114 | if ((flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) != 0) |
| 115 | strbuf << "HOST_VISIBLE"; |
| 116 | if ((flags & VK_MEMORY_PROPERTY_HOST_NON_COHERENT_BIT) != 0) |
| 117 | strbuf << " NON_COHERENT"; |
| 118 | if ((flags & VK_MEMORY_PROPERTY_HOST_UNCACHED_BIT) != 0) |
| 119 | strbuf << " UNCACHED"; |
| 120 | if ((flags & VK_MEMORY_PROPERTY_HOST_WRITE_COMBINED_BIT) != 0) |
| 121 | strbuf << " WRITE_COMBINED"; |
| 122 | if ((flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) != 0) |
| 123 | strbuf << " LAZILY_ALLOCATED"; |
| 124 | printf(" Type %u: %s\n", type, strbuf.str().c_str()); |
| 125 | strbuf.str(std::string()); |
| 126 | } |
| 127 | } |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | } // namespace |
| 131 | |
| 132 | int main(int /*argc*/, char const* /*argv*/ []) { |
| 133 | VkResult result; |
| 134 | |
| 135 | VkInstance instance; |
| 136 | const VkInstanceCreateInfo create_info = { |
| 137 | .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, |
| 138 | .pNext = nullptr, |
| 139 | .pAppInfo = nullptr, |
| 140 | .pAllocCb = nullptr, |
| 141 | .layerCount = 0, |
| 142 | .ppEnabledLayerNames = nullptr, |
| 143 | .extensionCount = 0, |
| 144 | .ppEnabledExtensionNames = nullptr, |
| 145 | }; |
| 146 | result = vkCreateInstance(&create_info, &instance); |
| 147 | if (result != VK_SUCCESS) |
| 148 | die("vkCreateInstance", result); |
| 149 | |
| 150 | uint32_t num_physical_devices; |
| 151 | result = |
| 152 | vkEnumeratePhysicalDevices(instance, &num_physical_devices, nullptr); |
| 153 | if (result != VK_SUCCESS) |
| 154 | die("vkEnumeratePhysicalDevices (count)", result); |
| 155 | std::vector<VkPhysicalDevice> physical_devices(num_physical_devices, |
| 156 | VK_NULL_HANDLE); |
| 157 | result = vkEnumeratePhysicalDevices(instance, &num_physical_devices, |
| 158 | physical_devices.data()); |
| 159 | if (result != VK_SUCCESS) |
| 160 | die("vkEnumeratePhysicalDevices (data)", result); |
| 161 | if (num_physical_devices != physical_devices.size()) { |
| 162 | fprintf(stderr, |
| 163 | "number of physical devices decreased from %zu to %u!\n", |
| 164 | physical_devices.size(), num_physical_devices); |
| 165 | physical_devices.resize(num_physical_devices); |
| 166 | } |
| 167 | printf("PhysicalDevices:\n"); |
| 168 | for (uint32_t i = 0; i < physical_devices.size(); i++) |
| 169 | DumpPhysicalDevice(i, physical_devices[i]); |
| 170 | |
| 171 | result = vkDestroyInstance(instance); |
| 172 | if (result != VK_SUCCESS) |
| 173 | die("vkDestroyInstance", result); |
| 174 | |
| 175 | return 0; |
| 176 | } |