Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | */ |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 24 | #include <stdlib.h> |
| 25 | #include <stdio.h> |
| 26 | #include <stdbool.h> |
| 27 | #include <string.h> |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 28 | #include <assert.h> |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 29 | |
Ian Elliott | ea95f5c | 2015-04-17 21:23:34 -0600 | [diff] [blame] | 30 | #ifdef _WIN32 |
| 31 | #include <Windows.h> |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 32 | #include <fcntl.h> |
| 33 | #include <io.h> |
Ian Elliott | ea95f5c | 2015-04-17 21:23:34 -0600 | [diff] [blame] | 34 | #endif |
| 35 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 36 | #include <vulkan.h> |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 37 | |
| 38 | #define ERR(err) printf("%s:%d: failed with %s\n", \ |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 39 | __FILE__, __LINE__, vk_result_string(err)); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 40 | |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 41 | #ifdef _WIN32 |
| 42 | |
Ian Elliott | 7c83aa2 | 2015-07-08 17:09:54 -0600 | [diff] [blame] | 43 | #define snprintf _snprintf |
| 44 | |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 45 | bool consoleCreated = false; |
| 46 | |
| 47 | #define WAIT_FOR_CONSOLE_DESTROY \ |
| 48 | do { \ |
| 49 | if (consoleCreated) \ |
| 50 | Sleep(INFINITE); \ |
| 51 | } while (0) |
| 52 | #else |
| 53 | #define WAIT_FOR_CONSOLE_DESTROY |
| 54 | #endif |
| 55 | |
| 56 | |
| 57 | #define ERR_EXIT(err) \ |
| 58 | do { \ |
| 59 | ERR(err); \ |
| 60 | fflush(stdout); \ |
| 61 | WAIT_FOR_CONSOLE_DESTROY; \ |
| 62 | exit(-1); \ |
| 63 | } while (0) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 64 | |
Tony Barbour | 22a3086 | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 65 | #if defined(NDEBUG) && defined(__GNUC__) |
| 66 | #define U_ASSERT_ONLY __attribute__((unused)) |
| 67 | #else |
| 68 | #define U_ASSERT_ONLY |
| 69 | #endif |
| 70 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 71 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 72 | |
| 73 | #define MAX_GPUS 8 |
| 74 | |
| 75 | #define MAX_QUEUE_TYPES 5 |
Ian Elliott | 4e19ed0 | 2015-04-28 10:52:52 -0600 | [diff] [blame] | 76 | #define APP_SHORT_NAME "vulkaninfo" |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 77 | |
| 78 | struct app_gpu; |
| 79 | |
| 80 | struct app_dev { |
| 81 | struct app_gpu *gpu; /* point back to the GPU */ |
| 82 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 83 | VkDevice obj; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 84 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 85 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 86 | VkFormatProperties format_props[VK_NUM_FORMAT]; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 87 | }; |
| 88 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 89 | struct layer_extension_list { |
| 90 | VkLayerProperties layer_properties; |
| 91 | uint32_t extension_count; |
| 92 | VkExtensionProperties *extension_properties; |
| 93 | }; |
| 94 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 95 | struct app_instance { |
| 96 | VkInstance instance; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 97 | uint32_t global_layer_count; |
| 98 | struct layer_extension_list *global_layers; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 99 | uint32_t global_extension_count; |
| 100 | VkExtensionProperties *global_extensions; |
| 101 | }; |
| 102 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 103 | struct app_gpu { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 104 | uint32_t id; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 105 | VkPhysicalDevice obj; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 106 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 107 | VkPhysicalDeviceProperties props; |
| 108 | VkPhysicalDevicePerformance perf; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 109 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 110 | uint32_t queue_count; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 111 | VkPhysicalDeviceQueueProperties *queue_props; |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 112 | VkDeviceQueueCreateInfo *queue_reqs; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 113 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 114 | VkPhysicalDeviceMemoryProperties memory_props; |
Chris Forbes | a048b31 | 2015-06-21 20:09:12 +1200 | [diff] [blame] | 115 | VkPhysicalDeviceFeatures features; |
| 116 | VkPhysicalDeviceLimits limits; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 117 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 118 | uint32_t device_layer_count; |
| 119 | struct layer_extension_list *device_layers; |
| 120 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 121 | uint32_t device_extension_count; |
| 122 | VkExtensionProperties *device_extensions; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 123 | |
| 124 | struct app_dev dev; |
| 125 | }; |
| 126 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 127 | static const char *vk_result_string(VkResult err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 128 | { |
| 129 | switch (err) { |
| 130 | #define STR(r) case r: return #r |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 131 | STR(VK_SUCCESS); |
| 132 | STR(VK_UNSUPPORTED); |
| 133 | STR(VK_NOT_READY); |
| 134 | STR(VK_TIMEOUT); |
| 135 | STR(VK_EVENT_SET); |
| 136 | STR(VK_EVENT_RESET); |
| 137 | STR(VK_ERROR_UNKNOWN); |
| 138 | STR(VK_ERROR_UNAVAILABLE); |
| 139 | STR(VK_ERROR_INITIALIZATION_FAILED); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 140 | STR(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 141 | STR(VK_ERROR_OUT_OF_DEVICE_MEMORY); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 142 | STR(VK_ERROR_DEVICE_ALREADY_CREATED); |
| 143 | STR(VK_ERROR_DEVICE_LOST); |
| 144 | STR(VK_ERROR_INVALID_POINTER); |
| 145 | STR(VK_ERROR_INVALID_VALUE); |
| 146 | STR(VK_ERROR_INVALID_HANDLE); |
| 147 | STR(VK_ERROR_INVALID_ORDINAL); |
| 148 | STR(VK_ERROR_INVALID_MEMORY_SIZE); |
| 149 | STR(VK_ERROR_INVALID_EXTENSION); |
| 150 | STR(VK_ERROR_INVALID_FLAGS); |
| 151 | STR(VK_ERROR_INVALID_ALIGNMENT); |
| 152 | STR(VK_ERROR_INVALID_FORMAT); |
| 153 | STR(VK_ERROR_INVALID_IMAGE); |
| 154 | STR(VK_ERROR_INVALID_DESCRIPTOR_SET_DATA); |
| 155 | STR(VK_ERROR_INVALID_QUEUE_TYPE); |
| 156 | STR(VK_ERROR_INVALID_OBJECT_TYPE); |
| 157 | STR(VK_ERROR_UNSUPPORTED_SHADER_IL_VERSION); |
| 158 | STR(VK_ERROR_BAD_SHADER_CODE); |
| 159 | STR(VK_ERROR_BAD_PIPELINE_DATA); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 160 | STR(VK_ERROR_NOT_MAPPABLE); |
| 161 | STR(VK_ERROR_MEMORY_MAP_FAILED); |
| 162 | STR(VK_ERROR_MEMORY_UNMAP_FAILED); |
| 163 | STR(VK_ERROR_INCOMPATIBLE_DEVICE); |
| 164 | STR(VK_ERROR_INCOMPATIBLE_DRIVER); |
| 165 | STR(VK_ERROR_INCOMPLETE_COMMAND_BUFFER); |
| 166 | STR(VK_ERROR_BUILDING_COMMAND_BUFFER); |
| 167 | STR(VK_ERROR_MEMORY_NOT_BOUND); |
| 168 | STR(VK_ERROR_INCOMPATIBLE_QUEUE); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 169 | #undef STR |
| 170 | default: return "UNKNOWN_RESULT"; |
| 171 | } |
| 172 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 173 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 174 | static const char *vk_physical_device_type_string(VkPhysicalDeviceType type) |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 175 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 176 | switch (type) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 177 | #define STR(r) case VK_PHYSICAL_DEVICE_TYPE_ ##r: return #r |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 178 | STR(OTHER); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 179 | STR(INTEGRATED_GPU); |
| 180 | STR(DISCRETE_GPU); |
| 181 | STR(VIRTUAL_GPU); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 182 | #undef STR |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 183 | default: return "UNKNOWN_DEVICE"; |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 184 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 185 | } |
| 186 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 187 | static const char *vk_format_string(VkFormat fmt) |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 188 | { |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 189 | switch (fmt) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 190 | #define STR(r) case VK_FORMAT_ ##r: return #r |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 191 | STR(UNDEFINED); |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 192 | STR(R4G4_UNORM); |
| 193 | STR(R4G4_USCALED); |
| 194 | STR(R4G4B4A4_UNORM); |
| 195 | STR(R4G4B4A4_USCALED); |
| 196 | STR(R5G6B5_UNORM); |
| 197 | STR(R5G6B5_USCALED); |
| 198 | STR(R5G5B5A1_UNORM); |
| 199 | STR(R5G5B5A1_USCALED); |
| 200 | STR(R8_UNORM); |
| 201 | STR(R8_SNORM); |
| 202 | STR(R8_USCALED); |
| 203 | STR(R8_SSCALED); |
| 204 | STR(R8_UINT); |
| 205 | STR(R8_SINT); |
| 206 | STR(R8_SRGB); |
| 207 | STR(R8G8_UNORM); |
| 208 | STR(R8G8_SNORM); |
| 209 | STR(R8G8_USCALED); |
| 210 | STR(R8G8_SSCALED); |
| 211 | STR(R8G8_UINT); |
| 212 | STR(R8G8_SINT); |
| 213 | STR(R8G8_SRGB); |
| 214 | STR(R8G8B8_UNORM); |
| 215 | STR(R8G8B8_SNORM); |
| 216 | STR(R8G8B8_USCALED); |
| 217 | STR(R8G8B8_SSCALED); |
| 218 | STR(R8G8B8_UINT); |
| 219 | STR(R8G8B8_SINT); |
| 220 | STR(R8G8B8_SRGB); |
| 221 | STR(R8G8B8A8_UNORM); |
| 222 | STR(R8G8B8A8_SNORM); |
| 223 | STR(R8G8B8A8_USCALED); |
| 224 | STR(R8G8B8A8_SSCALED); |
| 225 | STR(R8G8B8A8_UINT); |
| 226 | STR(R8G8B8A8_SINT); |
| 227 | STR(R8G8B8A8_SRGB); |
| 228 | STR(R10G10B10A2_UNORM); |
| 229 | STR(R10G10B10A2_SNORM); |
| 230 | STR(R10G10B10A2_USCALED); |
| 231 | STR(R10G10B10A2_SSCALED); |
| 232 | STR(R10G10B10A2_UINT); |
| 233 | STR(R10G10B10A2_SINT); |
| 234 | STR(R16_UNORM); |
| 235 | STR(R16_SNORM); |
| 236 | STR(R16_USCALED); |
| 237 | STR(R16_SSCALED); |
| 238 | STR(R16_UINT); |
| 239 | STR(R16_SINT); |
| 240 | STR(R16_SFLOAT); |
| 241 | STR(R16G16_UNORM); |
| 242 | STR(R16G16_SNORM); |
| 243 | STR(R16G16_USCALED); |
| 244 | STR(R16G16_SSCALED); |
| 245 | STR(R16G16_UINT); |
| 246 | STR(R16G16_SINT); |
| 247 | STR(R16G16_SFLOAT); |
| 248 | STR(R16G16B16_UNORM); |
| 249 | STR(R16G16B16_SNORM); |
| 250 | STR(R16G16B16_USCALED); |
| 251 | STR(R16G16B16_SSCALED); |
| 252 | STR(R16G16B16_UINT); |
| 253 | STR(R16G16B16_SINT); |
| 254 | STR(R16G16B16_SFLOAT); |
| 255 | STR(R16G16B16A16_UNORM); |
| 256 | STR(R16G16B16A16_SNORM); |
| 257 | STR(R16G16B16A16_USCALED); |
| 258 | STR(R16G16B16A16_SSCALED); |
| 259 | STR(R16G16B16A16_UINT); |
| 260 | STR(R16G16B16A16_SINT); |
| 261 | STR(R16G16B16A16_SFLOAT); |
| 262 | STR(R32_UINT); |
| 263 | STR(R32_SINT); |
| 264 | STR(R32_SFLOAT); |
| 265 | STR(R32G32_UINT); |
| 266 | STR(R32G32_SINT); |
| 267 | STR(R32G32_SFLOAT); |
| 268 | STR(R32G32B32_UINT); |
| 269 | STR(R32G32B32_SINT); |
| 270 | STR(R32G32B32_SFLOAT); |
| 271 | STR(R32G32B32A32_UINT); |
| 272 | STR(R32G32B32A32_SINT); |
| 273 | STR(R32G32B32A32_SFLOAT); |
| 274 | STR(R64_SFLOAT); |
| 275 | STR(R64G64_SFLOAT); |
| 276 | STR(R64G64B64_SFLOAT); |
| 277 | STR(R64G64B64A64_SFLOAT); |
| 278 | STR(R11G11B10_UFLOAT); |
| 279 | STR(R9G9B9E5_UFLOAT); |
| 280 | STR(D16_UNORM); |
| 281 | STR(D24_UNORM); |
| 282 | STR(D32_SFLOAT); |
| 283 | STR(S8_UINT); |
| 284 | STR(D16_UNORM_S8_UINT); |
| 285 | STR(D24_UNORM_S8_UINT); |
| 286 | STR(D32_SFLOAT_S8_UINT); |
Courtney Goeltzenleuchter | fe8a2e1 | 2015-03-03 11:30:36 -0700 | [diff] [blame] | 287 | STR(BC1_RGB_UNORM); |
| 288 | STR(BC1_RGB_SRGB); |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 289 | STR(BC2_UNORM); |
| 290 | STR(BC2_SRGB); |
| 291 | STR(BC3_UNORM); |
| 292 | STR(BC3_SRGB); |
| 293 | STR(BC4_UNORM); |
| 294 | STR(BC4_SNORM); |
| 295 | STR(BC5_UNORM); |
| 296 | STR(BC5_SNORM); |
| 297 | STR(BC6H_UFLOAT); |
| 298 | STR(BC6H_SFLOAT); |
| 299 | STR(BC7_UNORM); |
| 300 | STR(BC7_SRGB); |
| 301 | STR(ETC2_R8G8B8_UNORM); |
| 302 | STR(ETC2_R8G8B8A1_UNORM); |
| 303 | STR(ETC2_R8G8B8A8_UNORM); |
| 304 | STR(EAC_R11_UNORM); |
| 305 | STR(EAC_R11_SNORM); |
| 306 | STR(EAC_R11G11_UNORM); |
| 307 | STR(EAC_R11G11_SNORM); |
| 308 | STR(ASTC_4x4_UNORM); |
| 309 | STR(ASTC_4x4_SRGB); |
Courtney Goeltzenleuchter | fe8a2e1 | 2015-03-03 11:30:36 -0700 | [diff] [blame] | 310 | STR(ASTC_5x4_UNORM); |
| 311 | STR(ASTC_5x4_SRGB); |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 312 | STR(ASTC_5x5_UNORM); |
| 313 | STR(ASTC_5x5_SRGB); |
| 314 | STR(ASTC_6x5_UNORM); |
| 315 | STR(ASTC_6x5_SRGB); |
| 316 | STR(ASTC_6x6_UNORM); |
| 317 | STR(ASTC_6x6_SRGB); |
| 318 | STR(ASTC_8x5_UNORM); |
| 319 | STR(ASTC_8x5_SRGB); |
| 320 | STR(ASTC_8x6_UNORM); |
| 321 | STR(ASTC_8x6_SRGB); |
| 322 | STR(ASTC_8x8_UNORM); |
| 323 | STR(ASTC_8x8_SRGB); |
| 324 | STR(ASTC_10x5_UNORM); |
| 325 | STR(ASTC_10x5_SRGB); |
| 326 | STR(ASTC_10x6_UNORM); |
| 327 | STR(ASTC_10x6_SRGB); |
| 328 | STR(ASTC_10x8_UNORM); |
| 329 | STR(ASTC_10x8_SRGB); |
| 330 | STR(ASTC_10x10_UNORM); |
| 331 | STR(ASTC_10x10_SRGB); |
| 332 | STR(ASTC_12x10_UNORM); |
| 333 | STR(ASTC_12x10_SRGB); |
| 334 | STR(ASTC_12x12_UNORM); |
| 335 | STR(ASTC_12x12_SRGB); |
| 336 | STR(B5G6R5_UNORM); |
| 337 | STR(B5G6R5_USCALED); |
| 338 | STR(B8G8R8_UNORM); |
| 339 | STR(B8G8R8_SNORM); |
| 340 | STR(B8G8R8_USCALED); |
| 341 | STR(B8G8R8_SSCALED); |
| 342 | STR(B8G8R8_UINT); |
| 343 | STR(B8G8R8_SINT); |
| 344 | STR(B8G8R8_SRGB); |
| 345 | STR(B8G8R8A8_UNORM); |
| 346 | STR(B8G8R8A8_SNORM); |
| 347 | STR(B8G8R8A8_USCALED); |
| 348 | STR(B8G8R8A8_SSCALED); |
| 349 | STR(B8G8R8A8_UINT); |
| 350 | STR(B8G8R8A8_SINT); |
| 351 | STR(B8G8R8A8_SRGB); |
| 352 | STR(B10G10R10A2_UNORM); |
| 353 | STR(B10G10R10A2_SNORM); |
| 354 | STR(B10G10R10A2_USCALED); |
| 355 | STR(B10G10R10A2_SSCALED); |
| 356 | STR(B10G10R10A2_UINT); |
| 357 | STR(B10G10R10A2_SINT); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 358 | #undef STR |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 359 | default: return "UNKNOWN_FORMAT"; |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 360 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 361 | } |
| 362 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 363 | static void app_dev_init_formats(struct app_dev *dev) |
| 364 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 365 | VkFormat f; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 366 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 367 | for (f = 0; f < VK_NUM_FORMAT; f++) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 368 | const VkFormat fmt = f; |
| 369 | VkResult err; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 370 | |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 371 | err = vkGetPhysicalDeviceFormatInfo(dev->gpu->obj, fmt, &dev->format_props[f]); |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 372 | if (err) { |
| 373 | memset(&dev->format_props[f], 0, |
| 374 | sizeof(dev->format_props[f])); |
| 375 | } |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 379 | static void extract_version(uint32_t version, uint32_t *major, uint32_t *minor, uint32_t *patch) |
| 380 | { |
| 381 | *major = version >> 22; |
| 382 | *minor = (version >> 12) & 0x3ff; |
| 383 | *patch = version & 0xfff; |
| 384 | } |
| 385 | |
| 386 | static void app_get_physical_device_layer_extensions( |
| 387 | struct app_gpu *gpu, |
| 388 | char *layer_name, |
| 389 | uint32_t *extension_count, |
| 390 | VkExtensionProperties **extension_properties) |
| 391 | { |
| 392 | VkResult err; |
| 393 | uint32_t ext_count = 0; |
| 394 | VkExtensionProperties *ext_ptr = NULL; |
| 395 | |
| 396 | /* repeat get until VK_INCOMPLETE goes away */ |
| 397 | do { |
| 398 | err = vkGetPhysicalDeviceExtensionProperties(gpu->obj, layer_name, &ext_count, NULL); |
| 399 | assert(!err); |
| 400 | |
| 401 | if (ext_ptr) { |
| 402 | free(ext_ptr); |
| 403 | } |
| 404 | ext_ptr = malloc(ext_count * sizeof(VkExtensionProperties)); |
| 405 | err = vkGetPhysicalDeviceExtensionProperties(gpu->obj, layer_name, &ext_count, ext_ptr); |
| 406 | } while (err == VK_INCOMPLETE); |
| 407 | assert(!err); |
| 408 | |
| 409 | *extension_count = ext_count; |
| 410 | *extension_properties = ext_ptr; |
| 411 | } |
| 412 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 413 | static void app_dev_init(struct app_dev *dev, struct app_gpu *gpu) |
| 414 | { |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 415 | VkDeviceCreateInfo info = { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 416 | .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 417 | .pNext = NULL, |
| 418 | .queueRecordCount = 0, |
| 419 | .pRequestedQueues = NULL, |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 420 | .layerCount = 0, |
| 421 | .ppEnabledLayerNames = NULL, |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 422 | .extensionCount = 0, |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 423 | .ppEnabledExtensionNames = NULL, |
Jon Ashburn | 80d3b71 | 2015-05-18 09:06:15 -0600 | [diff] [blame] | 424 | .flags = 0, |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 425 | }; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 426 | VkResult U_ASSERT_ONLY err; |
| 427 | // Extensions to enable |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 428 | static const char *known_extensions[] = { |
Jon Ashburn | fcff043 | 2015-07-10 13:51:52 -0600 | [diff] [blame] | 429 | //TODO add WSI device extension WSI swapchain, WSI_LUNARG is a global extension |
David Pinedo | 793c729 | 2015-07-10 16:37:31 -0600 | [diff] [blame] | 430 | "" |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 431 | }; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 432 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 433 | uint32_t count = 0; |
| 434 | |
| 435 | /* Scan layers */ |
| 436 | VkLayerProperties *device_layer_properties = NULL; |
| 437 | struct layer_extension_list *device_layers = NULL; |
| 438 | |
| 439 | do { |
| 440 | err = vkGetPhysicalDeviceLayerProperties(gpu->obj, &count, NULL); |
| 441 | assert(!err); |
| 442 | |
| 443 | if (device_layer_properties) { |
| 444 | free(device_layer_properties); |
| 445 | } |
| 446 | device_layer_properties = malloc(sizeof(VkLayerProperties) * count); |
| 447 | assert(device_layer_properties); |
| 448 | |
| 449 | if (device_layers) { |
| 450 | free(device_layers); |
| 451 | } |
| 452 | device_layers = malloc(sizeof(struct layer_extension_list) * count); |
| 453 | assert(device_layers); |
| 454 | |
| 455 | err = vkGetPhysicalDeviceLayerProperties(gpu->obj, &count, device_layer_properties); |
| 456 | } while (err == VK_INCOMPLETE); |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 457 | assert(!err); |
| 458 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 459 | gpu->device_layer_count = count; |
| 460 | gpu->device_layers = device_layers; |
| 461 | |
| 462 | for (uint32_t i = 0; i < gpu->device_layer_count; i++) { |
| 463 | VkLayerProperties *src_info = &device_layer_properties[i]; |
| 464 | struct layer_extension_list *dst_info = &gpu->device_layers[i]; |
| 465 | memcpy(&dst_info->layer_properties, src_info, sizeof(VkLayerProperties)); |
| 466 | |
| 467 | /* Save away layer extension info for report */ |
| 468 | app_get_physical_device_layer_extensions( |
| 469 | gpu, |
| 470 | src_info->layerName, |
| 471 | &dst_info->extension_count, |
| 472 | &dst_info->extension_properties); |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 473 | } |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 474 | free(device_layer_properties); |
| 475 | |
| 476 | app_get_physical_device_layer_extensions( |
| 477 | gpu, |
| 478 | NULL, |
| 479 | &gpu->device_extension_count, |
| 480 | &gpu->device_extensions); |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 481 | |
Courtney Goeltzenleuchter | 9e42b88 | 2015-06-25 16:24:36 -0600 | [diff] [blame] | 482 | fflush(stdout); |
| 483 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 484 | uint32_t enabled_extension_count = 0; |
Courtney Goeltzenleuchter | 67a0741 | 2015-07-10 10:10:27 -0600 | [diff] [blame] | 485 | uint32_t known_extension_count = ARRAY_SIZE(known_extensions); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 486 | |
Courtney Goeltzenleuchter | 67a0741 | 2015-07-10 10:10:27 -0600 | [diff] [blame] | 487 | for (uint32_t i = 0; i < known_extension_count; i++) { |
Courtney Goeltzenleuchter | 1f41f54 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 488 | VkBool32 extension_found = 0; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 489 | for (uint32_t j = 0; j < gpu->device_extension_count; j++) { |
| 490 | VkExtensionProperties *ext_prop = &gpu->device_extensions[j]; |
| 491 | if (!strcmp(known_extensions[i], ext_prop->extName)) { |
| 492 | |
| 493 | extension_found = 1; |
| 494 | enabled_extension_count++; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 495 | } |
| 496 | } |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 497 | if (!extension_found) { |
| 498 | printf("Cannot find extension: %s\n", known_extensions[i]); |
| 499 | ERR_EXIT(VK_ERROR_INVALID_EXTENSION); |
| 500 | } |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 501 | } |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 502 | |
| 503 | /* request all queues */ |
| 504 | info.queueRecordCount = gpu->queue_count; |
| 505 | info.pRequestedQueues = gpu->queue_reqs; |
| 506 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 507 | info.layerCount = 0; |
| 508 | info.ppEnabledLayerNames = NULL; |
| 509 | info.extensionCount = enabled_extension_count; |
| 510 | info.ppEnabledExtensionNames = (const char*const*) known_extensions; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 511 | dev->gpu = gpu; |
| 512 | err = vkCreateDevice(gpu->obj, &info, &dev->obj); |
| 513 | if (err) |
| 514 | ERR_EXIT(err); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 515 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static void app_dev_destroy(struct app_dev *dev) |
| 519 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 520 | vkDestroyDevice(dev->obj); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 521 | } |
| 522 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 523 | static void app_get_global_layer_extensions( |
| 524 | char *layer_name, |
| 525 | uint32_t *extension_count, |
| 526 | VkExtensionProperties **extension_properties) |
| 527 | { |
| 528 | VkResult err; |
| 529 | uint32_t ext_count = 0; |
| 530 | VkExtensionProperties *ext_ptr = NULL; |
| 531 | |
| 532 | /* repeat get until VK_INCOMPLETE goes away */ |
| 533 | do { |
| 534 | err = vkGetGlobalExtensionProperties(layer_name, &ext_count, NULL); |
| 535 | assert(!err); |
| 536 | |
| 537 | if (ext_ptr) { |
| 538 | free(ext_ptr); |
| 539 | } |
| 540 | ext_ptr = malloc(ext_count * sizeof(VkExtensionProperties)); |
| 541 | err = vkGetGlobalExtensionProperties(layer_name, &ext_count, ext_ptr); |
| 542 | } while (err == VK_INCOMPLETE); |
| 543 | assert(!err); |
| 544 | |
| 545 | *extension_count = ext_count; |
| 546 | *extension_properties = ext_ptr; |
| 547 | } |
| 548 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 549 | static void app_create_instance(struct app_instance *inst) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 550 | { |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 551 | const VkApplicationInfo app_info = { |
| 552 | .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, |
| 553 | .pNext = NULL, |
| 554 | .pAppName = APP_SHORT_NAME, |
| 555 | .appVersion = 1, |
| 556 | .pEngineName = APP_SHORT_NAME, |
| 557 | .engineVersion = 1, |
| 558 | .apiVersion = VK_API_VERSION, |
| 559 | }; |
| 560 | VkInstanceCreateInfo inst_info = { |
| 561 | .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, |
| 562 | .pNext = NULL, |
| 563 | .pAppInfo = &app_info, |
| 564 | .pAllocCb = NULL, |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 565 | .layerCount = 0, |
| 566 | .ppEnabledLayerNames = NULL, |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 567 | .extensionCount = 0, |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 568 | .ppEnabledExtensionNames = NULL, |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 569 | }; |
Tony Barbour | 22a3086 | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 570 | VkResult U_ASSERT_ONLY err; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 571 | // Global Extensions to enable |
Ian Elliott | aae1a57 | 2015-02-04 16:48:37 -0700 | [diff] [blame] | 572 | static char *known_extensions[] = { |
Tobin Ehlis | 97b4c5d | 2015-04-17 14:05:23 -0600 | [diff] [blame] | 573 | "VK_WSI_LunarG", |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 574 | }; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 575 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 576 | uint32_t global_extension_count = 0; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 577 | uint32_t count = 0; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 578 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 579 | /* Scan layers */ |
| 580 | VkLayerProperties *global_layer_properties = NULL; |
| 581 | struct layer_extension_list *global_layers = NULL; |
| 582 | |
| 583 | do { |
| 584 | err = vkGetGlobalLayerProperties(&count, NULL); |
| 585 | assert(!err); |
| 586 | |
| 587 | if (global_layer_properties) { |
| 588 | free(global_layer_properties); |
| 589 | } |
| 590 | global_layer_properties = malloc(sizeof(VkLayerProperties) * count); |
| 591 | assert(global_layer_properties); |
| 592 | |
| 593 | if (global_layers) { |
| 594 | free(global_layers); |
| 595 | } |
| 596 | global_layers = malloc(sizeof(struct layer_extension_list) * count); |
| 597 | assert(global_layers); |
| 598 | |
| 599 | err = vkGetGlobalLayerProperties(&count, global_layer_properties); |
| 600 | } while (err == VK_INCOMPLETE); |
Tobin Ehlis | 3536b44 | 2015-04-16 18:04:57 -0600 | [diff] [blame] | 601 | assert(!err); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 602 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 603 | inst->global_layer_count = count; |
| 604 | inst->global_layers = global_layers; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 605 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 606 | for (uint32_t i = 0; i < inst->global_layer_count; i++) { |
| 607 | VkLayerProperties *src_info = &global_layer_properties[i]; |
| 608 | struct layer_extension_list *dst_info = &inst->global_layers[i]; |
| 609 | memcpy(&dst_info->layer_properties, src_info, sizeof(VkLayerProperties)); |
| 610 | |
| 611 | /* Save away layer extension info for report */ |
| 612 | app_get_global_layer_extensions( |
| 613 | src_info->layerName, |
| 614 | &dst_info->extension_count, |
| 615 | &dst_info->extension_properties); |
| 616 | } |
| 617 | free(global_layer_properties); |
| 618 | |
| 619 | /* Collect global extensions */ |
| 620 | inst->global_extension_count = 0; |
| 621 | app_get_global_layer_extensions( |
| 622 | NULL, |
| 623 | &inst->global_extension_count, |
| 624 | &inst->global_extensions); |
| 625 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 626 | for (uint32_t i = 0; i < ARRAY_SIZE(known_extensions); i++) { |
Courtney Goeltzenleuchter | 1f41f54 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 627 | VkBool32 extension_found = 0; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 628 | for (uint32_t j = 0; j < inst->global_extension_count; j++) { |
| 629 | VkExtensionProperties *extension_prop = &inst->global_extensions[j]; |
| 630 | if (!strcmp(known_extensions[i], extension_prop->extName)) { |
| 631 | |
| 632 | extension_found = 1; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 633 | global_extension_count++; |
| 634 | } |
Tobin Ehlis | 3536b44 | 2015-04-16 18:04:57 -0600 | [diff] [blame] | 635 | } |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 636 | if (!extension_found) { |
| 637 | printf("Cannot find extension: %s\n", known_extensions[i]); |
| 638 | ERR_EXIT(VK_ERROR_INVALID_EXTENSION); |
| 639 | } |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 640 | } |
| 641 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 642 | inst_info.extensionCount = global_extension_count; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 643 | inst_info.ppEnabledExtensionNames = (const char * const *) known_extensions; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 644 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 645 | err = vkCreateInstance(&inst_info, &inst->instance); |
| 646 | if (err == VK_ERROR_INCOMPATIBLE_DRIVER) { |
| 647 | printf("Cannot create Vulkan instance.\n"); |
| 648 | ERR_EXIT(err); |
| 649 | } else if (err) { |
| 650 | ERR_EXIT(err); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 654 | static void app_destroy_instance(struct app_instance *inst) |
| 655 | { |
| 656 | free(inst->global_extensions); |
| 657 | vkDestroyInstance(inst->instance); |
| 658 | } |
| 659 | |
| 660 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 661 | static void app_gpu_init(struct app_gpu *gpu, uint32_t id, VkPhysicalDevice obj) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 662 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 663 | VkResult err; |
Ian Elliott | aae1a57 | 2015-02-04 16:48:37 -0700 | [diff] [blame] | 664 | uint32_t i; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 665 | |
| 666 | memset(gpu, 0, sizeof(*gpu)); |
| 667 | |
| 668 | gpu->id = id; |
| 669 | gpu->obj = obj; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 670 | |
| 671 | err = vkGetPhysicalDeviceProperties(gpu->obj, &gpu->props); |
| 672 | if (err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 673 | ERR_EXIT(err); |
| 674 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 675 | err = vkGetPhysicalDevicePerformance(gpu->obj, &gpu->perf); |
| 676 | if (err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 677 | ERR_EXIT(err); |
| 678 | |
| 679 | /* get queue count */ |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 680 | err = vkGetPhysicalDeviceQueueCount(gpu->obj, &gpu->queue_count); |
| 681 | if (err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 682 | ERR_EXIT(err); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 683 | |
| 684 | gpu->queue_props = |
| 685 | malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 686 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 687 | if (!gpu->queue_props) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 688 | ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 689 | err = vkGetPhysicalDeviceQueueProperties(gpu->obj, gpu->queue_count, gpu->queue_props); |
| 690 | if (err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 691 | ERR_EXIT(err); |
| 692 | |
| 693 | /* set up queue requests */ |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 694 | gpu->queue_reqs = malloc(sizeof(*gpu->queue_reqs) * gpu->queue_count); |
| 695 | if (!gpu->queue_reqs) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 696 | ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 697 | for (i = 0; i < gpu->queue_count; i++) { |
| 698 | gpu->queue_reqs[i].queueNodeIndex = i; |
| 699 | gpu->queue_reqs[i].queueCount = gpu->queue_props[i].queueCount; |
| 700 | } |
| 701 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 702 | err = vkGetPhysicalDeviceMemoryProperties(gpu->obj, &gpu->memory_props); |
| 703 | if (err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 704 | ERR_EXIT(err); |
| 705 | |
Chris Forbes | a048b31 | 2015-06-21 20:09:12 +1200 | [diff] [blame] | 706 | err = vkGetPhysicalDeviceFeatures(gpu->obj, &gpu->features); |
| 707 | if (err) |
| 708 | ERR_EXIT(err); |
| 709 | |
| 710 | err = vkGetPhysicalDeviceLimits(gpu->obj, &gpu->limits); |
| 711 | if (err) |
| 712 | ERR_EXIT(err); |
| 713 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 714 | app_dev_init(&gpu->dev, gpu); |
| 715 | app_dev_init_formats(&gpu->dev); |
| 716 | } |
| 717 | |
| 718 | static void app_gpu_destroy(struct app_gpu *gpu) |
| 719 | { |
| 720 | app_dev_destroy(&gpu->dev); |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 721 | free(gpu->device_extensions); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 722 | free(gpu->queue_reqs); |
| 723 | free(gpu->queue_props); |
| 724 | } |
| 725 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 726 | static void app_dev_dump_format_props(const struct app_dev *dev, VkFormat fmt) |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 727 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 728 | const VkFormatProperties *props = &dev->format_props[fmt]; |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 729 | struct { |
| 730 | const char *name; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 731 | VkFlags flags; |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 732 | } tilings[2]; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 733 | uint32_t i; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 734 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 735 | if (!props->linearTilingFeatures && !props->optimalTilingFeatures) |
| 736 | return; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 737 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 738 | tilings[0].name = "linear"; |
| 739 | tilings[0].flags = props->linearTilingFeatures; |
| 740 | tilings[1].name = "optimal"; |
| 741 | tilings[1].flags = props->optimalTilingFeatures; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 742 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 743 | printf("FORMAT_%s\n", vk_format_string(fmt)); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 744 | for (i = 0; i < ARRAY_SIZE(tilings); i++) { |
| 745 | if (!tilings[i].flags) |
| 746 | continue; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 747 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 748 | printf("\t%s tiling image =%s%s%s\n", tilings[i].name, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 749 | (tilings[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) ? " sampled" : "", |
| 750 | (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) ? " storage" : "", |
| 751 | (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT) ? " atomic" : ""); |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 752 | printf("\t%s tiling texel =%s%s%s\n", tilings[i].name, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 753 | (tilings[i].flags & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT) ? " TBO" : "", |
| 754 | (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT) ? " IBO" : "", |
| 755 | (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT) ? " atomic" : ""); |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 756 | printf("\t%s tiling attachment =%s%s%s\n", tilings[i].name, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 757 | (tilings[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) ? " color" : "", |
| 758 | (tilings[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT) ? " blend" : "", |
| 759 | (tilings[i].flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) ? " depth/stencil" : ""); |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 760 | printf("\t%s tiling vertex = %u\n", tilings[i].name, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 761 | (bool) (tilings[i].flags & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT)); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 762 | printf("\t%s tiling conversion = %u\n", tilings[i].name, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 763 | (bool) (tilings[i].flags & VK_FORMAT_FEATURE_CONVERSION_BIT)); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 764 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 765 | } |
| 766 | |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 767 | |
| 768 | static void |
| 769 | app_dev_dump(const struct app_dev *dev) |
| 770 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 771 | VkFormat fmt; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 772 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 773 | for (fmt = 0; fmt < VK_NUM_FORMAT; fmt++) { |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 774 | app_dev_dump_format_props(dev, fmt); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 775 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 776 | } |
| 777 | |
Mike Stroyan | 009d8ca | 2015-05-27 13:09:15 -0600 | [diff] [blame] | 778 | #ifdef _WIN32 |
| 779 | #define PRINTF_SIZE_T_SPECIFIER "%Iu" |
| 780 | #else |
| 781 | #define PRINTF_SIZE_T_SPECIFIER "%zu" |
| 782 | #endif |
| 783 | |
Chris Forbes | a048b31 | 2015-06-21 20:09:12 +1200 | [diff] [blame] | 784 | static void app_gpu_dump_features(const struct app_gpu *gpu) |
| 785 | { |
| 786 | const VkPhysicalDeviceFeatures *features = &gpu->features; |
| 787 | |
| 788 | printf("VkPhysicalDeviceFeatures\n"); |
| 789 | /* TODO: add interesting features */ |
| 790 | printf("\tgeometryShader = %u\n", features->geometryShader); |
| 791 | } |
| 792 | |
| 793 | static void app_gpu_dump_limits(const struct app_gpu *gpu) |
| 794 | { |
| 795 | const VkPhysicalDeviceLimits *limits = &gpu->limits; |
| 796 | |
| 797 | printf("VkPhysicalDeviceLimits\n"); |
| 798 | /* TODO: add interesting limits */ |
| 799 | printf("\tmaxInlineMemoryUpdateSize = " PRINTF_SIZE_T_SPECIFIER "\n", limits->maxInlineMemoryUpdateSize); |
| 800 | printf("\tmaxBoundDescriptorSets = %u\n", limits->maxBoundDescriptorSets); |
| 801 | printf("\tmaxComputeWorkGroupInvocations = %u\n", limits->maxComputeWorkGroupInvocations); |
| 802 | printf("\ttimestampFrequency = %lu\n", limits->timestampFrequency); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 803 | } |
| 804 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 805 | static void app_gpu_dump_props(const struct app_gpu *gpu) |
| 806 | { |
| 807 | const VkPhysicalDeviceProperties *props = &gpu->props; |
| 808 | |
| 809 | printf("VkPhysicalDeviceProperties\n"); |
| 810 | printf("\tapiVersion = %u\n", props->apiVersion); |
| 811 | printf("\tdriverVersion = %u\n", props->driverVersion); |
| 812 | printf("\tvendorId = 0x%04x\n", props->vendorId); |
| 813 | printf("\tdeviceId = 0x%04x\n", props->deviceId); |
| 814 | printf("\tdeviceType = %s\n", vk_physical_device_type_string(props->deviceType)); |
| 815 | printf("\tdeviceName = %s\n", props->deviceName); |
| 816 | fflush(stdout); |
| 817 | } |
| 818 | |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 819 | static void app_gpu_dump_perf(const struct app_gpu *gpu) |
| 820 | { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 821 | const VkPhysicalDevicePerformance *perf = &gpu->perf; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 822 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 823 | printf("VkPhysicalDevicePerformance\n"); |
| 824 | printf("\tmaxGpuClock = %f\n", perf->maxDeviceClock); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 825 | printf("\taluPerClock = %f\n", perf->aluPerClock); |
| 826 | printf("\ttexPerClock = %f\n", perf->texPerClock); |
| 827 | printf("\tprimsPerClock = %f\n", perf->primsPerClock); |
| 828 | printf("\tpixelsPerClock = %f\n", perf->pixelsPerClock); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 829 | fflush(stdout); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 830 | } |
| 831 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 832 | static void app_dump_extensions( |
| 833 | const char *indent, |
| 834 | const char *layer_name, |
| 835 | const uint32_t extension_count, |
| 836 | const VkExtensionProperties *extension_properties) |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 837 | { |
| 838 | uint32_t i; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 839 | if (layer_name && (strlen(layer_name) > 0)) { |
| 840 | printf("%s%s Extensions", indent, layer_name); |
| 841 | } else { |
| 842 | printf("Extensions"); |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 843 | } |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 844 | printf("\tcount = %d\n", extension_count); |
| 845 | for (i=0; i< extension_count; i++) { |
| 846 | uint32_t major, minor, patch; |
| 847 | char spec_version[64], extension_version[64]; |
| 848 | VkExtensionProperties const *ext_prop = &extension_properties[i]; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 849 | |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 850 | if (i>0) |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 851 | printf("\n"); // separator between extensions |
| 852 | |
| 853 | printf("%s\t", indent); |
| 854 | extract_version(ext_prop->specVersion, &major, &minor, &patch); |
| 855 | snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", major, minor, patch); |
| 856 | extract_version(ext_prop->version, &major, &minor, &patch); |
| 857 | snprintf(extension_version, sizeof(extension_version), "%d.%d.%d", major, minor, patch); |
| 858 | printf("%s: Vulkan version %s, extension version %s", |
| 859 | ext_prop->extName, spec_version, extension_version); |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 860 | } |
| 861 | printf("\n"); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 862 | fflush(stdout); |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 863 | } |
| 864 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 865 | static void app_gpu_dump_queue_props(const struct app_gpu *gpu, uint32_t id) |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 866 | { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 867 | const VkPhysicalDeviceQueueProperties *props = &gpu->queue_props[id]; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 868 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 869 | printf("VkPhysicalDeviceQueueProperties[%d]\n", id); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 870 | printf("\tqueueFlags = %c%c%c%c\n", |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 871 | (props->queueFlags & VK_QUEUE_GRAPHICS_BIT) ? 'G' : '.', |
| 872 | (props->queueFlags & VK_QUEUE_COMPUTE_BIT) ? 'C' : '.', |
| 873 | (props->queueFlags & VK_QUEUE_DMA_BIT) ? 'D' : '.', |
| 874 | (props->queueFlags & VK_QUEUE_EXTENDED_BIT) ? 'X' : '.'); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 875 | printf("\tqueueCount = %u\n", props->queueCount); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 876 | printf("\tsupportsTimestamps = %u\n", props->supportsTimestamps); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 877 | fflush(stdout); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | static void app_gpu_dump_memory_props(const struct app_gpu *gpu) |
| 881 | { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 882 | const VkPhysicalDeviceMemoryProperties *props = &gpu->memory_props; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 883 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 884 | printf("VkPhysicalDeviceMemoryProperties\n"); |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 885 | printf("\tmemoryTypeCount = %u\n", props->memoryTypeCount); |
| 886 | for (uint32_t i = 0; i < props->memoryTypeCount; i++) { |
| 887 | printf("\tmemoryTypes[%u] : \n", i); |
| 888 | printf("\t\tpropertyFlags = %u\n", props->memoryTypes[i].propertyFlags); |
| 889 | printf("\t\theapIndex = %u\n", props->memoryTypes[i].heapIndex); |
| 890 | } |
| 891 | printf("\tmemoryHeapCount = %u\n", props->memoryHeapCount); |
| 892 | for (uint32_t i = 0; i < props->memoryHeapCount; i++) { |
| 893 | printf("\tmemoryHeaps[%u] : \n", i); |
| 894 | printf("\t\tsize = " PRINTF_SIZE_T_SPECIFIER "\n", props->memoryHeaps[i].size); |
| 895 | } |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 896 | fflush(stdout); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | static void app_gpu_dump(const struct app_gpu *gpu) |
| 900 | { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 901 | uint32_t i; |
Chia-I Wu | f5c46f4 | 2014-08-05 15:33:40 +0800 | [diff] [blame] | 902 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 903 | printf("GPU%u\n", gpu->id); |
| 904 | app_gpu_dump_props(gpu); |
| 905 | printf("\n"); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 906 | app_dump_extensions("", "", gpu->device_extension_count, gpu->device_extensions); |
| 907 | printf("\n"); |
| 908 | printf("Layers\tcount = %d\n", gpu->device_layer_count); |
| 909 | for (uint32_t i = 0; i < gpu->device_layer_count; i++) { |
| 910 | uint32_t major, minor, patch; |
| 911 | char spec_version[64], layer_version[64]; |
| 912 | struct layer_extension_list const *layer_info = &gpu->device_layers[i]; |
| 913 | |
| 914 | extract_version(layer_info->layer_properties.specVersion, &major, &minor, &patch); |
| 915 | snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", major, minor, patch); |
| 916 | extract_version(layer_info->layer_properties.implVersion, &major, &minor, &patch); |
| 917 | snprintf(layer_version, sizeof(layer_version), "%d.%d.%d", major, minor, patch); |
| 918 | printf("\t%s (%s) Vulkan version %s, layer version %s\n", |
| 919 | layer_info->layer_properties.layerName, |
| 920 | layer_info->layer_properties.description, |
| 921 | spec_version, layer_version); |
| 922 | |
| 923 | app_dump_extensions("\t", |
| 924 | layer_info->layer_properties.layerName, |
| 925 | layer_info->extension_count, |
| 926 | layer_info->extension_properties); |
| 927 | fflush(stdout); |
| 928 | } |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 929 | printf("\n"); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 930 | app_gpu_dump_perf(gpu); |
| 931 | printf("\n"); |
| 932 | for (i = 0; i < gpu->queue_count; i++) { |
| 933 | app_gpu_dump_queue_props(gpu, i); |
| 934 | printf("\n"); |
| 935 | } |
| 936 | app_gpu_dump_memory_props(gpu); |
| 937 | printf("\n"); |
Chris Forbes | a048b31 | 2015-06-21 20:09:12 +1200 | [diff] [blame] | 938 | app_gpu_dump_features(gpu); |
| 939 | printf("\n"); |
| 940 | app_gpu_dump_limits(gpu); |
| 941 | printf("\n"); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 942 | app_dev_dump(&gpu->dev); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 943 | } |
| 944 | |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 945 | int main(int argc, char **argv) |
| 946 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 947 | struct app_gpu gpus[MAX_GPUS]; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 948 | VkPhysicalDevice objs[MAX_GPUS]; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 949 | uint32_t gpu_count, i; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 950 | VkResult err; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 951 | struct app_instance inst; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 952 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 953 | app_create_instance(&inst); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 954 | app_dump_extensions("", "Global", inst.global_extension_count, inst.global_extensions); |
| 955 | |
| 956 | printf("Global Layers\tcount = %d\n", inst.global_layer_count); |
| 957 | for (uint32_t i = 0; i < inst.global_layer_count; i++) { |
| 958 | uint32_t major, minor, patch; |
| 959 | char spec_version[64], layer_version[64]; |
| 960 | VkLayerProperties const *layer_prop = &inst.global_layers[i].layer_properties; |
| 961 | |
| 962 | extract_version(layer_prop->specVersion, &major, &minor, &patch); |
| 963 | snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", major, minor, patch); |
| 964 | extract_version(layer_prop->implVersion, &major, &minor, &patch); |
| 965 | snprintf(layer_version, sizeof(layer_version), "%d.%d.%d", major, minor, patch); |
| 966 | printf("\t%s (%s) Vulkan version %s, layer version %s\n", |
| 967 | layer_prop->layerName, layer_prop->description, spec_version, layer_version); |
| 968 | |
| 969 | app_dump_extensions("\t", |
| 970 | inst.global_layers[i].layer_properties.layerName, |
| 971 | inst.global_layers[i].extension_count, |
| 972 | inst.global_layers[i].extension_properties); |
| 973 | } |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 974 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 975 | err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, NULL); |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 976 | if (err) |
| 977 | ERR_EXIT(err); |
| 978 | if (gpu_count > MAX_GPUS) { |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 979 | printf("Too many GPUS found \n"); |
| 980 | ERR_EXIT(VK_ERROR_UNKNOWN); |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 981 | } |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 982 | err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, objs); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 983 | if (err) |
| 984 | ERR_EXIT(err); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 985 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 986 | for (i = 0; i < gpu_count; i++) { |
| 987 | app_gpu_init(&gpus[i], i, objs[i]); |
| 988 | app_gpu_dump(&gpus[i]); |
| 989 | printf("\n\n"); |
| 990 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 991 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 992 | for (i = 0; i < gpu_count; i++) |
| 993 | app_gpu_destroy(&gpus[i]); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 994 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 995 | app_destroy_instance(&inst); |
Chia-I Wu | 0b9a737 | 2014-08-06 12:09:19 +0800 | [diff] [blame] | 996 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 997 | return 0; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 998 | } |
Ian Elliott | ea95f5c | 2015-04-17 21:23:34 -0600 | [diff] [blame] | 999 | |
| 1000 | #ifdef _WIN32 |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 1001 | |
| 1002 | // Create a console window with a large scrollback size to which to send stdout. |
| 1003 | // Returns true if console window was successfully created, false otherwise. |
| 1004 | bool SetStdOutToNewConsole() |
| 1005 | { |
| 1006 | // don't do anything if we already have a console |
| 1007 | if (GetStdHandle(STD_OUTPUT_HANDLE)) |
| 1008 | return false; |
| 1009 | |
| 1010 | // allocate a console for this app |
| 1011 | AllocConsole(); |
| 1012 | |
| 1013 | // redirect unbuffered STDOUT to the console |
| 1014 | HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); |
| 1015 | int fileDescriptor = _open_osfhandle((intptr_t)consoleHandle, _O_TEXT); |
| 1016 | FILE *fp = _fdopen( fileDescriptor, "w" ); |
| 1017 | *stdout = *fp; |
| 1018 | setvbuf( stdout, NULL, _IONBF, 0 ); |
| 1019 | |
| 1020 | // make the console window bigger |
| 1021 | CONSOLE_SCREEN_BUFFER_INFO csbi; |
| 1022 | SMALL_RECT r; |
| 1023 | COORD bufferSize; |
| 1024 | if (!GetConsoleScreenBufferInfo(consoleHandle, &csbi)) |
| 1025 | return false; |
| 1026 | bufferSize.X = csbi.dwSize.X; |
| 1027 | bufferSize.Y = 1000; |
| 1028 | if (!SetConsoleScreenBufferSize(consoleHandle, bufferSize)) |
| 1029 | return false; |
| 1030 | r.Left = r.Top = 0; |
| 1031 | r.Right = csbi.dwSize.X-1; |
| 1032 | r.Bottom = 60; |
| 1033 | if (!SetConsoleWindowInfo(consoleHandle, true, &r)) |
| 1034 | return false; |
| 1035 | |
| 1036 | // change the console window title |
Ian Elliott | 4e19ed0 | 2015-04-28 10:52:52 -0600 | [diff] [blame] | 1037 | if (!SetConsoleTitle(TEXT(APP_SHORT_NAME))) |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 1038 | return false; |
| 1039 | |
| 1040 | return true; |
| 1041 | } |
| 1042 | |
Ian Elliott | ea95f5c | 2015-04-17 21:23:34 -0600 | [diff] [blame] | 1043 | int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nCmdShow) |
| 1044 | { |
| 1045 | char *argv = pCmdLine; |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 1046 | consoleCreated = SetStdOutToNewConsole(); |
Ian Elliott | ea95f5c | 2015-04-17 21:23:34 -0600 | [diff] [blame] | 1047 | main(1, &argv); |
| 1048 | fflush(stdout); |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 1049 | if (consoleCreated) |
| 1050 | Sleep(INFINITE); |
Ian Elliott | ea95f5c | 2015-04-17 21:23:34 -0600 | [diff] [blame] | 1051 | } |
| 1052 | #endif |