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 | |
| 43 | bool consoleCreated = false; |
| 44 | |
| 45 | #define WAIT_FOR_CONSOLE_DESTROY \ |
| 46 | do { \ |
| 47 | if (consoleCreated) \ |
| 48 | Sleep(INFINITE); \ |
| 49 | } while (0) |
| 50 | #else |
| 51 | #define WAIT_FOR_CONSOLE_DESTROY |
| 52 | #endif |
| 53 | |
| 54 | |
| 55 | #define ERR_EXIT(err) \ |
| 56 | do { \ |
| 57 | ERR(err); \ |
| 58 | fflush(stdout); \ |
| 59 | WAIT_FOR_CONSOLE_DESTROY; \ |
| 60 | exit(-1); \ |
| 61 | } while (0) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 62 | |
Tony Barbour | 22a3086 | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 63 | #if defined(NDEBUG) && defined(__GNUC__) |
| 64 | #define U_ASSERT_ONLY __attribute__((unused)) |
| 65 | #else |
| 66 | #define U_ASSERT_ONLY |
| 67 | #endif |
| 68 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 69 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 70 | |
| 71 | #define MAX_GPUS 8 |
| 72 | |
| 73 | #define MAX_QUEUE_TYPES 5 |
Ian Elliott | 4e19ed0 | 2015-04-28 10:52:52 -0600 | [diff] [blame] | 74 | #define APP_SHORT_NAME "vulkaninfo" |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 75 | |
| 76 | struct app_gpu; |
| 77 | |
| 78 | struct app_dev { |
| 79 | struct app_gpu *gpu; /* point back to the GPU */ |
| 80 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 81 | VkDevice obj; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 82 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 83 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 84 | VkFormatProperties format_props[VK_NUM_FORMAT]; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 85 | }; |
| 86 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 87 | struct app_instance { |
| 88 | VkInstance instance; |
| 89 | uint32_t global_extension_count; |
| 90 | VkExtensionProperties *global_extensions; |
| 91 | }; |
| 92 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 93 | struct app_gpu { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 94 | uint32_t id; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 95 | VkPhysicalDevice obj; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 96 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 97 | VkPhysicalDeviceProperties props; |
| 98 | VkPhysicalDevicePerformance perf; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 99 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 100 | uint32_t queue_count; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 101 | VkPhysicalDeviceQueueProperties *queue_props; |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 102 | VkDeviceQueueCreateInfo *queue_reqs; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 103 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 104 | VkPhysicalDeviceMemoryProperties memory_props; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 105 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 106 | uint32_t device_extension_count; |
| 107 | VkExtensionProperties *device_extensions; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 108 | |
| 109 | struct app_dev dev; |
| 110 | }; |
| 111 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 112 | static const char *vk_result_string(VkResult err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 113 | { |
| 114 | switch (err) { |
| 115 | #define STR(r) case r: return #r |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 116 | STR(VK_SUCCESS); |
| 117 | STR(VK_UNSUPPORTED); |
| 118 | STR(VK_NOT_READY); |
| 119 | STR(VK_TIMEOUT); |
| 120 | STR(VK_EVENT_SET); |
| 121 | STR(VK_EVENT_RESET); |
| 122 | STR(VK_ERROR_UNKNOWN); |
| 123 | STR(VK_ERROR_UNAVAILABLE); |
| 124 | STR(VK_ERROR_INITIALIZATION_FAILED); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 125 | STR(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 126 | STR(VK_ERROR_OUT_OF_DEVICE_MEMORY); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 127 | STR(VK_ERROR_DEVICE_ALREADY_CREATED); |
| 128 | STR(VK_ERROR_DEVICE_LOST); |
| 129 | STR(VK_ERROR_INVALID_POINTER); |
| 130 | STR(VK_ERROR_INVALID_VALUE); |
| 131 | STR(VK_ERROR_INVALID_HANDLE); |
| 132 | STR(VK_ERROR_INVALID_ORDINAL); |
| 133 | STR(VK_ERROR_INVALID_MEMORY_SIZE); |
| 134 | STR(VK_ERROR_INVALID_EXTENSION); |
| 135 | STR(VK_ERROR_INVALID_FLAGS); |
| 136 | STR(VK_ERROR_INVALID_ALIGNMENT); |
| 137 | STR(VK_ERROR_INVALID_FORMAT); |
| 138 | STR(VK_ERROR_INVALID_IMAGE); |
| 139 | STR(VK_ERROR_INVALID_DESCRIPTOR_SET_DATA); |
| 140 | STR(VK_ERROR_INVALID_QUEUE_TYPE); |
| 141 | STR(VK_ERROR_INVALID_OBJECT_TYPE); |
| 142 | STR(VK_ERROR_UNSUPPORTED_SHADER_IL_VERSION); |
| 143 | STR(VK_ERROR_BAD_SHADER_CODE); |
| 144 | STR(VK_ERROR_BAD_PIPELINE_DATA); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 145 | STR(VK_ERROR_NOT_MAPPABLE); |
| 146 | STR(VK_ERROR_MEMORY_MAP_FAILED); |
| 147 | STR(VK_ERROR_MEMORY_UNMAP_FAILED); |
| 148 | STR(VK_ERROR_INCOMPATIBLE_DEVICE); |
| 149 | STR(VK_ERROR_INCOMPATIBLE_DRIVER); |
| 150 | STR(VK_ERROR_INCOMPLETE_COMMAND_BUFFER); |
| 151 | STR(VK_ERROR_BUILDING_COMMAND_BUFFER); |
| 152 | STR(VK_ERROR_MEMORY_NOT_BOUND); |
| 153 | STR(VK_ERROR_INCOMPATIBLE_QUEUE); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 154 | #undef STR |
| 155 | default: return "UNKNOWN_RESULT"; |
| 156 | } |
| 157 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 158 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 159 | static const char *vk_physical_device_type_string(VkPhysicalDeviceType type) |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 160 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 161 | switch (type) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 162 | #define STR(r) case VK_PHYSICAL_DEVICE_TYPE_ ##r: return #r |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 163 | STR(OTHER); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 164 | STR(INTEGRATED_GPU); |
| 165 | STR(DISCRETE_GPU); |
| 166 | STR(VIRTUAL_GPU); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 167 | #undef STR |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 168 | default: return "UNKNOWN_DEVICE"; |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 169 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 170 | } |
| 171 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 172 | static const char *vk_format_string(VkFormat fmt) |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 173 | { |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 174 | switch (fmt) { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 175 | #define STR(r) case VK_FORMAT_ ##r: return #r |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 176 | STR(UNDEFINED); |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 177 | STR(R4G4_UNORM); |
| 178 | STR(R4G4_USCALED); |
| 179 | STR(R4G4B4A4_UNORM); |
| 180 | STR(R4G4B4A4_USCALED); |
| 181 | STR(R5G6B5_UNORM); |
| 182 | STR(R5G6B5_USCALED); |
| 183 | STR(R5G5B5A1_UNORM); |
| 184 | STR(R5G5B5A1_USCALED); |
| 185 | STR(R8_UNORM); |
| 186 | STR(R8_SNORM); |
| 187 | STR(R8_USCALED); |
| 188 | STR(R8_SSCALED); |
| 189 | STR(R8_UINT); |
| 190 | STR(R8_SINT); |
| 191 | STR(R8_SRGB); |
| 192 | STR(R8G8_UNORM); |
| 193 | STR(R8G8_SNORM); |
| 194 | STR(R8G8_USCALED); |
| 195 | STR(R8G8_SSCALED); |
| 196 | STR(R8G8_UINT); |
| 197 | STR(R8G8_SINT); |
| 198 | STR(R8G8_SRGB); |
| 199 | STR(R8G8B8_UNORM); |
| 200 | STR(R8G8B8_SNORM); |
| 201 | STR(R8G8B8_USCALED); |
| 202 | STR(R8G8B8_SSCALED); |
| 203 | STR(R8G8B8_UINT); |
| 204 | STR(R8G8B8_SINT); |
| 205 | STR(R8G8B8_SRGB); |
| 206 | STR(R8G8B8A8_UNORM); |
| 207 | STR(R8G8B8A8_SNORM); |
| 208 | STR(R8G8B8A8_USCALED); |
| 209 | STR(R8G8B8A8_SSCALED); |
| 210 | STR(R8G8B8A8_UINT); |
| 211 | STR(R8G8B8A8_SINT); |
| 212 | STR(R8G8B8A8_SRGB); |
| 213 | STR(R10G10B10A2_UNORM); |
| 214 | STR(R10G10B10A2_SNORM); |
| 215 | STR(R10G10B10A2_USCALED); |
| 216 | STR(R10G10B10A2_SSCALED); |
| 217 | STR(R10G10B10A2_UINT); |
| 218 | STR(R10G10B10A2_SINT); |
| 219 | STR(R16_UNORM); |
| 220 | STR(R16_SNORM); |
| 221 | STR(R16_USCALED); |
| 222 | STR(R16_SSCALED); |
| 223 | STR(R16_UINT); |
| 224 | STR(R16_SINT); |
| 225 | STR(R16_SFLOAT); |
| 226 | STR(R16G16_UNORM); |
| 227 | STR(R16G16_SNORM); |
| 228 | STR(R16G16_USCALED); |
| 229 | STR(R16G16_SSCALED); |
| 230 | STR(R16G16_UINT); |
| 231 | STR(R16G16_SINT); |
| 232 | STR(R16G16_SFLOAT); |
| 233 | STR(R16G16B16_UNORM); |
| 234 | STR(R16G16B16_SNORM); |
| 235 | STR(R16G16B16_USCALED); |
| 236 | STR(R16G16B16_SSCALED); |
| 237 | STR(R16G16B16_UINT); |
| 238 | STR(R16G16B16_SINT); |
| 239 | STR(R16G16B16_SFLOAT); |
| 240 | STR(R16G16B16A16_UNORM); |
| 241 | STR(R16G16B16A16_SNORM); |
| 242 | STR(R16G16B16A16_USCALED); |
| 243 | STR(R16G16B16A16_SSCALED); |
| 244 | STR(R16G16B16A16_UINT); |
| 245 | STR(R16G16B16A16_SINT); |
| 246 | STR(R16G16B16A16_SFLOAT); |
| 247 | STR(R32_UINT); |
| 248 | STR(R32_SINT); |
| 249 | STR(R32_SFLOAT); |
| 250 | STR(R32G32_UINT); |
| 251 | STR(R32G32_SINT); |
| 252 | STR(R32G32_SFLOAT); |
| 253 | STR(R32G32B32_UINT); |
| 254 | STR(R32G32B32_SINT); |
| 255 | STR(R32G32B32_SFLOAT); |
| 256 | STR(R32G32B32A32_UINT); |
| 257 | STR(R32G32B32A32_SINT); |
| 258 | STR(R32G32B32A32_SFLOAT); |
| 259 | STR(R64_SFLOAT); |
| 260 | STR(R64G64_SFLOAT); |
| 261 | STR(R64G64B64_SFLOAT); |
| 262 | STR(R64G64B64A64_SFLOAT); |
| 263 | STR(R11G11B10_UFLOAT); |
| 264 | STR(R9G9B9E5_UFLOAT); |
| 265 | STR(D16_UNORM); |
| 266 | STR(D24_UNORM); |
| 267 | STR(D32_SFLOAT); |
| 268 | STR(S8_UINT); |
| 269 | STR(D16_UNORM_S8_UINT); |
| 270 | STR(D24_UNORM_S8_UINT); |
| 271 | STR(D32_SFLOAT_S8_UINT); |
Courtney Goeltzenleuchter | fe8a2e1 | 2015-03-03 11:30:36 -0700 | [diff] [blame] | 272 | STR(BC1_RGB_UNORM); |
| 273 | STR(BC1_RGB_SRGB); |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 274 | STR(BC2_UNORM); |
| 275 | STR(BC2_SRGB); |
| 276 | STR(BC3_UNORM); |
| 277 | STR(BC3_SRGB); |
| 278 | STR(BC4_UNORM); |
| 279 | STR(BC4_SNORM); |
| 280 | STR(BC5_UNORM); |
| 281 | STR(BC5_SNORM); |
| 282 | STR(BC6H_UFLOAT); |
| 283 | STR(BC6H_SFLOAT); |
| 284 | STR(BC7_UNORM); |
| 285 | STR(BC7_SRGB); |
| 286 | STR(ETC2_R8G8B8_UNORM); |
| 287 | STR(ETC2_R8G8B8A1_UNORM); |
| 288 | STR(ETC2_R8G8B8A8_UNORM); |
| 289 | STR(EAC_R11_UNORM); |
| 290 | STR(EAC_R11_SNORM); |
| 291 | STR(EAC_R11G11_UNORM); |
| 292 | STR(EAC_R11G11_SNORM); |
| 293 | STR(ASTC_4x4_UNORM); |
| 294 | STR(ASTC_4x4_SRGB); |
Courtney Goeltzenleuchter | fe8a2e1 | 2015-03-03 11:30:36 -0700 | [diff] [blame] | 295 | STR(ASTC_5x4_UNORM); |
| 296 | STR(ASTC_5x4_SRGB); |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 297 | STR(ASTC_5x5_UNORM); |
| 298 | STR(ASTC_5x5_SRGB); |
| 299 | STR(ASTC_6x5_UNORM); |
| 300 | STR(ASTC_6x5_SRGB); |
| 301 | STR(ASTC_6x6_UNORM); |
| 302 | STR(ASTC_6x6_SRGB); |
| 303 | STR(ASTC_8x5_UNORM); |
| 304 | STR(ASTC_8x5_SRGB); |
| 305 | STR(ASTC_8x6_UNORM); |
| 306 | STR(ASTC_8x6_SRGB); |
| 307 | STR(ASTC_8x8_UNORM); |
| 308 | STR(ASTC_8x8_SRGB); |
| 309 | STR(ASTC_10x5_UNORM); |
| 310 | STR(ASTC_10x5_SRGB); |
| 311 | STR(ASTC_10x6_UNORM); |
| 312 | STR(ASTC_10x6_SRGB); |
| 313 | STR(ASTC_10x8_UNORM); |
| 314 | STR(ASTC_10x8_SRGB); |
| 315 | STR(ASTC_10x10_UNORM); |
| 316 | STR(ASTC_10x10_SRGB); |
| 317 | STR(ASTC_12x10_UNORM); |
| 318 | STR(ASTC_12x10_SRGB); |
| 319 | STR(ASTC_12x12_UNORM); |
| 320 | STR(ASTC_12x12_SRGB); |
| 321 | STR(B5G6R5_UNORM); |
| 322 | STR(B5G6R5_USCALED); |
| 323 | STR(B8G8R8_UNORM); |
| 324 | STR(B8G8R8_SNORM); |
| 325 | STR(B8G8R8_USCALED); |
| 326 | STR(B8G8R8_SSCALED); |
| 327 | STR(B8G8R8_UINT); |
| 328 | STR(B8G8R8_SINT); |
| 329 | STR(B8G8R8_SRGB); |
| 330 | STR(B8G8R8A8_UNORM); |
| 331 | STR(B8G8R8A8_SNORM); |
| 332 | STR(B8G8R8A8_USCALED); |
| 333 | STR(B8G8R8A8_SSCALED); |
| 334 | STR(B8G8R8A8_UINT); |
| 335 | STR(B8G8R8A8_SINT); |
| 336 | STR(B8G8R8A8_SRGB); |
| 337 | STR(B10G10R10A2_UNORM); |
| 338 | STR(B10G10R10A2_SNORM); |
| 339 | STR(B10G10R10A2_USCALED); |
| 340 | STR(B10G10R10A2_SSCALED); |
| 341 | STR(B10G10R10A2_UINT); |
| 342 | STR(B10G10R10A2_SINT); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 343 | #undef STR |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 344 | default: return "UNKNOWN_FORMAT"; |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 345 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 346 | } |
| 347 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 348 | static void app_dev_init_formats(struct app_dev *dev) |
| 349 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 350 | VkFormat f; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 351 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 352 | for (f = 0; f < VK_NUM_FORMAT; f++) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 353 | const VkFormat fmt = f; |
| 354 | VkResult err; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 355 | |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 356 | err = vkGetPhysicalDeviceFormatInfo(dev->gpu->obj, fmt, &dev->format_props[f]); |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 357 | if (err) { |
| 358 | memset(&dev->format_props[f], 0, |
| 359 | sizeof(dev->format_props[f])); |
| 360 | } |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
| 364 | static void app_dev_init(struct app_dev *dev, struct app_gpu *gpu) |
| 365 | { |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 366 | VkDeviceCreateInfo info = { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 367 | .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 368 | .pNext = NULL, |
| 369 | .queueRecordCount = 0, |
| 370 | .pRequestedQueues = NULL, |
| 371 | .extensionCount = 0, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 372 | .pEnabledExtensions = NULL, |
Jon Ashburn | 80d3b71 | 2015-05-18 09:06:15 -0600 | [diff] [blame] | 373 | .flags = 0, |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 374 | }; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 375 | VkResult U_ASSERT_ONLY err; |
| 376 | // Extensions to enable |
| 377 | VkExtensionProperties *enable_extension_list; |
| 378 | static char *known_extensions[] = { |
Courtney Goeltzenleuchter | e880e9b | 2015-06-25 16:23:45 -0600 | [diff] [blame] | 379 | "VK_WSI_LunarG", |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 380 | "Validation", |
| 381 | }; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 382 | |
| 383 | uint32_t extCount; |
| 384 | err = vkGetPhysicalDeviceExtensionCount(gpu->obj, &extCount); |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 385 | assert(!err); |
| 386 | |
| 387 | enable_extension_list = malloc(sizeof(VkExtensionProperties) * extCount); |
| 388 | if (!enable_extension_list) { |
| 389 | ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 390 | } |
| 391 | |
Courtney Goeltzenleuchter | 9e42b88 | 2015-06-25 16:24:36 -0600 | [diff] [blame^] | 392 | fflush(stdout); |
| 393 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 394 | VkExtensionProperties extProp; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 395 | gpu->device_extension_count = 0; |
| 396 | bool32_t U_ASSERT_ONLY extFound = 0; // TODO : Need to enhance this if/when we enable multiple extensions |
| 397 | for (uint32_t i = 0; i < ARRAY_SIZE(known_extensions); i++) { |
| 398 | for (uint32_t j = 0; j < extCount; j++) { |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 399 | err = vkGetPhysicalDeviceExtensionProperties( |
| 400 | gpu->obj, j, &extProp); |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 401 | if (!strcmp(known_extensions[i], extProp.name)) { |
| 402 | extFound = 1; |
| 403 | memcpy(&enable_extension_list[gpu->device_extension_count], &extProp, sizeof(extProp)); |
| 404 | gpu->device_extension_count++; |
Courtney Goeltzenleuchter | 9e42b88 | 2015-06-25 16:24:36 -0600 | [diff] [blame^] | 405 | printf("%s: %s\n", extProp.name, extProp.description); |
| 406 | fflush(stdout); |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | } |
| 410 | assert(extFound); |
| 411 | |
| 412 | gpu->device_extensions = enable_extension_list; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 413 | |
| 414 | /* request all queues */ |
| 415 | info.queueRecordCount = gpu->queue_count; |
| 416 | info.pRequestedQueues = gpu->queue_reqs; |
| 417 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 418 | info.extensionCount = extCount; |
| 419 | info.pEnabledExtensions = enable_extension_list; |
| 420 | dev->gpu = gpu; |
| 421 | err = vkCreateDevice(gpu->obj, &info, &dev->obj); |
| 422 | if (err) |
| 423 | ERR_EXIT(err); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 424 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | static void app_dev_destroy(struct app_dev *dev) |
| 428 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 429 | vkDestroyDevice(dev->obj); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 430 | } |
| 431 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 432 | static void app_create_instance(struct app_instance *inst) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 433 | { |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 434 | const VkApplicationInfo app_info = { |
| 435 | .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, |
| 436 | .pNext = NULL, |
| 437 | .pAppName = APP_SHORT_NAME, |
| 438 | .appVersion = 1, |
| 439 | .pEngineName = APP_SHORT_NAME, |
| 440 | .engineVersion = 1, |
| 441 | .apiVersion = VK_API_VERSION, |
| 442 | }; |
| 443 | VkInstanceCreateInfo inst_info = { |
| 444 | .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, |
| 445 | .pNext = NULL, |
| 446 | .pAppInfo = &app_info, |
| 447 | .pAllocCb = NULL, |
| 448 | .extensionCount = 0, |
| 449 | .pEnabledExtensions = NULL, |
| 450 | }; |
Tony Barbour | 22a3086 | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 451 | VkResult U_ASSERT_ONLY err; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 452 | // Global Extensions to enable |
Ian Elliott | aae1a57 | 2015-02-04 16:48:37 -0700 | [diff] [blame] | 453 | static char *known_extensions[] = { |
Tobin Ehlis | 97b4c5d | 2015-04-17 14:05:23 -0600 | [diff] [blame] | 454 | "VK_WSI_LunarG", |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 455 | }; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 456 | |
Tobin Ehlis | 3536b44 | 2015-04-16 18:04:57 -0600 | [diff] [blame] | 457 | uint32_t extCount = 0; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 458 | VkExtensionProperties extProp; |
| 459 | VkExtensionProperties *enable_extension_list; |
| 460 | uint32_t global_extension_count = 0; |
| 461 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 462 | err = vkGetGlobalExtensionCount(&extCount); |
Tobin Ehlis | 3536b44 | 2015-04-16 18:04:57 -0600 | [diff] [blame] | 463 | assert(!err); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 464 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 465 | enable_extension_list = malloc(sizeof(VkExtensionProperties) * extCount); |
| 466 | if (!enable_extension_list) { |
| 467 | ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); |
| 468 | } |
| 469 | |
Tony Barbour | 22a3086 | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 470 | bool32_t U_ASSERT_ONLY extFound = 0; // TODO : Need to enhance this if/when we enable multiple extensions |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 471 | for (uint32_t i = 0; i < ARRAY_SIZE(known_extensions); i++) { |
| 472 | for (uint32_t j = 0; j < extCount; j++) { |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 473 | err = vkGetGlobalExtensionProperties(j, &extProp); |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 474 | if (!strcmp(known_extensions[i], extProp.name)) { |
| 475 | extFound = 1; |
| 476 | memcpy(&enable_extension_list[global_extension_count], &extProp, sizeof(extProp)); |
| 477 | global_extension_count++; |
| 478 | } |
Tobin Ehlis | 3536b44 | 2015-04-16 18:04:57 -0600 | [diff] [blame] | 479 | } |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 480 | } |
Tobin Ehlis | 3536b44 | 2015-04-16 18:04:57 -0600 | [diff] [blame] | 481 | assert(extFound); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 482 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 483 | inst_info.extensionCount = global_extension_count; |
| 484 | inst_info.pEnabledExtensions = enable_extension_list; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 485 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 486 | err = vkCreateInstance(&inst_info, &inst->instance); |
| 487 | if (err == VK_ERROR_INCOMPATIBLE_DRIVER) { |
| 488 | printf("Cannot create Vulkan instance.\n"); |
| 489 | ERR_EXIT(err); |
| 490 | } else if (err) { |
| 491 | ERR_EXIT(err); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 492 | } |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 493 | |
| 494 | inst->global_extension_count = global_extension_count; |
| 495 | inst->global_extensions = enable_extension_list; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 496 | } |
| 497 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 498 | static void app_destroy_instance(struct app_instance *inst) |
| 499 | { |
| 500 | free(inst->global_extensions); |
| 501 | vkDestroyInstance(inst->instance); |
| 502 | } |
| 503 | |
| 504 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 505 | 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] | 506 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 507 | VkResult err; |
Ian Elliott | aae1a57 | 2015-02-04 16:48:37 -0700 | [diff] [blame] | 508 | uint32_t i; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 509 | |
| 510 | memset(gpu, 0, sizeof(*gpu)); |
| 511 | |
| 512 | gpu->id = id; |
| 513 | gpu->obj = obj; |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 514 | |
| 515 | err = vkGetPhysicalDeviceProperties(gpu->obj, &gpu->props); |
| 516 | if (err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 517 | ERR_EXIT(err); |
| 518 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 519 | err = vkGetPhysicalDevicePerformance(gpu->obj, &gpu->perf); |
| 520 | if (err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 521 | ERR_EXIT(err); |
| 522 | |
| 523 | /* get queue count */ |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 524 | err = vkGetPhysicalDeviceQueueCount(gpu->obj, &gpu->queue_count); |
| 525 | if (err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 526 | ERR_EXIT(err); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 527 | |
| 528 | gpu->queue_props = |
| 529 | malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 530 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 531 | if (!gpu->queue_props) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 532 | ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 533 | err = vkGetPhysicalDeviceQueueProperties(gpu->obj, gpu->queue_count, gpu->queue_props); |
| 534 | if (err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 535 | ERR_EXIT(err); |
| 536 | |
| 537 | /* set up queue requests */ |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 538 | gpu->queue_reqs = malloc(sizeof(*gpu->queue_reqs) * gpu->queue_count); |
| 539 | if (!gpu->queue_reqs) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 540 | ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 541 | for (i = 0; i < gpu->queue_count; i++) { |
| 542 | gpu->queue_reqs[i].queueNodeIndex = i; |
| 543 | gpu->queue_reqs[i].queueCount = gpu->queue_props[i].queueCount; |
| 544 | } |
| 545 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 546 | err = vkGetPhysicalDeviceMemoryProperties(gpu->obj, &gpu->memory_props); |
| 547 | if (err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 548 | ERR_EXIT(err); |
| 549 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 550 | app_dev_init(&gpu->dev, gpu); |
| 551 | app_dev_init_formats(&gpu->dev); |
| 552 | } |
| 553 | |
| 554 | static void app_gpu_destroy(struct app_gpu *gpu) |
| 555 | { |
| 556 | app_dev_destroy(&gpu->dev); |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 557 | free(gpu->device_extensions); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 558 | free(gpu->queue_reqs); |
| 559 | free(gpu->queue_props); |
| 560 | } |
| 561 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 562 | 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] | 563 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 564 | const VkFormatProperties *props = &dev->format_props[fmt]; |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 565 | struct { |
| 566 | const char *name; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 567 | VkFlags flags; |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 568 | } tilings[2]; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 569 | uint32_t i; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 570 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 571 | if (!props->linearTilingFeatures && !props->optimalTilingFeatures) |
| 572 | return; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 573 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 574 | tilings[0].name = "linear"; |
| 575 | tilings[0].flags = props->linearTilingFeatures; |
| 576 | tilings[1].name = "optimal"; |
| 577 | tilings[1].flags = props->optimalTilingFeatures; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 578 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 579 | printf("FORMAT_%s\n", vk_format_string(fmt)); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 580 | for (i = 0; i < ARRAY_SIZE(tilings); i++) { |
| 581 | if (!tilings[i].flags) |
| 582 | continue; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 583 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 584 | printf("\t%s tiling image =%s%s%s\n", tilings[i].name, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 585 | (tilings[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) ? " sampled" : "", |
| 586 | (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) ? " storage" : "", |
| 587 | (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT) ? " atomic" : ""); |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 588 | printf("\t%s tiling texel =%s%s%s\n", tilings[i].name, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 589 | (tilings[i].flags & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT) ? " TBO" : "", |
| 590 | (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT) ? " IBO" : "", |
| 591 | (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT) ? " atomic" : ""); |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 592 | printf("\t%s tiling attachment =%s%s%s\n", tilings[i].name, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 593 | (tilings[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) ? " color" : "", |
| 594 | (tilings[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT) ? " blend" : "", |
| 595 | (tilings[i].flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) ? " depth/stencil" : ""); |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 596 | printf("\t%s tiling vertex = %u\n", tilings[i].name, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 597 | (bool) (tilings[i].flags & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT)); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 598 | printf("\t%s tiling conversion = %u\n", tilings[i].name, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 599 | (bool) (tilings[i].flags & VK_FORMAT_FEATURE_CONVERSION_BIT)); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 600 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 601 | } |
| 602 | |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 603 | |
| 604 | static void |
| 605 | app_dev_dump(const struct app_dev *dev) |
| 606 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 607 | VkFormat fmt; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 608 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 609 | for (fmt = 0; fmt < VK_NUM_FORMAT; fmt++) { |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 610 | app_dev_dump_format_props(dev, fmt); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 611 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 612 | } |
| 613 | |
Mike Stroyan | 009d8ca | 2015-05-27 13:09:15 -0600 | [diff] [blame] | 614 | #ifdef _WIN32 |
| 615 | #define PRINTF_SIZE_T_SPECIFIER "%Iu" |
| 616 | #else |
| 617 | #define PRINTF_SIZE_T_SPECIFIER "%zu" |
| 618 | #endif |
| 619 | |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 620 | static void app_gpu_dump_props(const struct app_gpu *gpu) |
| 621 | { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 622 | const VkPhysicalDeviceProperties *props = &gpu->props; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 623 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 624 | printf("VkPhysicalDeviceProperties\n"); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 625 | printf("\tapiVersion = %u\n", props->apiVersion); |
| 626 | printf("\tdriverVersion = %u\n", props->driverVersion); |
| 627 | printf("\tvendorId = 0x%04x\n", props->vendorId); |
| 628 | printf("\tdeviceId = 0x%04x\n", props->deviceId); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 629 | printf("\tdeviceType = %s\n", vk_physical_device_type_string(props->deviceType)); |
| 630 | printf("\tdeviceName = %s\n", props->deviceName); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 631 | printf("\tmaxBoundDescriptorSets = %u\n", props->maxBoundDescriptorSets); |
| 632 | printf("\tmaxThreadGroupSize = %u\n", props->maxThreadGroupSize); |
| 633 | printf("\ttimestampFrequency = %lu\n", props->timestampFrequency); |
| 634 | printf("\tmultiColorAttachmentClears = %u\n", props->multiColorAttachmentClears); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | static void app_gpu_dump_perf(const struct app_gpu *gpu) |
| 638 | { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 639 | const VkPhysicalDevicePerformance *perf = &gpu->perf; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 640 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 641 | printf("VkPhysicalDevicePerformance\n"); |
| 642 | printf("\tmaxGpuClock = %f\n", perf->maxDeviceClock); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 643 | printf("\taluPerClock = %f\n", perf->aluPerClock); |
| 644 | printf("\ttexPerClock = %f\n", perf->texPerClock); |
| 645 | printf("\tprimsPerClock = %f\n", perf->primsPerClock); |
| 646 | printf("\tpixelsPerClock = %f\n", perf->pixelsPerClock); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 647 | } |
| 648 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 649 | static void app_gpu_dump_instance_extensions(const struct app_instance *inst) |
| 650 | { |
| 651 | uint32_t i; |
| 652 | printf("Extensions"); |
| 653 | printf("\tcount = %d\n", inst->global_extension_count); |
| 654 | printf("\t"); |
| 655 | for (i=0; i< inst->global_extension_count; i++) { |
| 656 | if (i>0) |
| 657 | printf(", "); // separator between extension names |
| 658 | printf("%s", inst->global_extensions[i].name); |
| 659 | } |
| 660 | printf("\n"); |
| 661 | } |
| 662 | |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 663 | static void app_gpu_dump_extensions(const struct app_gpu *gpu) |
| 664 | { |
Ian Elliott | aae1a57 | 2015-02-04 16:48:37 -0700 | [diff] [blame] | 665 | uint32_t i; |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 666 | printf("Extensions"); |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 667 | printf("\tcount = %d\n", gpu->device_extension_count); |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 668 | printf("\t"); |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 669 | for (i=0; i< gpu->device_extension_count; i++) { |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 670 | if (i>0) |
| 671 | printf(", "); // separator between extension names |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 672 | printf("%s(%d): %s", gpu->device_extensions[i].name, |
| 673 | gpu->device_extensions[i].version, |
| 674 | gpu->device_extensions[i].description); |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 675 | } |
| 676 | printf("\n"); |
| 677 | } |
| 678 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 679 | 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] | 680 | { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 681 | const VkPhysicalDeviceQueueProperties *props = &gpu->queue_props[id]; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 682 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 683 | printf("VkPhysicalDeviceQueueProperties[%d]\n", id); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 684 | printf("\tqueueFlags = %c%c%c%c\n", |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 685 | (props->queueFlags & VK_QUEUE_GRAPHICS_BIT) ? 'G' : '.', |
| 686 | (props->queueFlags & VK_QUEUE_COMPUTE_BIT) ? 'C' : '.', |
| 687 | (props->queueFlags & VK_QUEUE_DMA_BIT) ? 'D' : '.', |
| 688 | (props->queueFlags & VK_QUEUE_EXTENDED_BIT) ? 'X' : '.'); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 689 | printf("\tqueueCount = %u\n", props->queueCount); |
| 690 | printf("\tmaxAtomicCounters = %u\n", props->maxAtomicCounters); |
| 691 | printf("\tsupportsTimestamps = %u\n", props->supportsTimestamps); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | static void app_gpu_dump_memory_props(const struct app_gpu *gpu) |
| 695 | { |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 696 | const VkPhysicalDeviceMemoryProperties *props = &gpu->memory_props; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 697 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 698 | printf("VkPhysicalDeviceMemoryProperties\n"); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 699 | printf("\tsupportsMigration = %u\n", props->supportsMigration); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | static void app_gpu_dump(const struct app_gpu *gpu) |
| 703 | { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 704 | uint32_t i; |
Chia-I Wu | f5c46f4 | 2014-08-05 15:33:40 +0800 | [diff] [blame] | 705 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 706 | printf("GPU%u\n", gpu->id); |
| 707 | app_gpu_dump_props(gpu); |
| 708 | printf("\n"); |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 709 | app_gpu_dump_extensions(gpu); |
| 710 | printf("\n"); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 711 | app_gpu_dump_perf(gpu); |
| 712 | printf("\n"); |
| 713 | for (i = 0; i < gpu->queue_count; i++) { |
| 714 | app_gpu_dump_queue_props(gpu, i); |
| 715 | printf("\n"); |
| 716 | } |
| 717 | app_gpu_dump_memory_props(gpu); |
| 718 | printf("\n"); |
| 719 | app_dev_dump(&gpu->dev); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 720 | } |
| 721 | |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 722 | int main(int argc, char **argv) |
| 723 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 724 | struct app_gpu gpus[MAX_GPUS]; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 725 | VkPhysicalDevice objs[MAX_GPUS]; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 726 | uint32_t gpu_count, i; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 727 | VkResult err; |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 728 | struct app_instance inst; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 729 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 730 | app_create_instance(&inst); |
| 731 | app_gpu_dump_instance_extensions(&inst); |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 732 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 733 | err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, NULL); |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 734 | if (err) |
| 735 | ERR_EXIT(err); |
| 736 | if (gpu_count > MAX_GPUS) { |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 737 | printf("Too many GPUS found \n"); |
| 738 | ERR_EXIT(VK_ERROR_UNKNOWN); |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 739 | } |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 740 | err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, objs); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 741 | if (err) |
| 742 | ERR_EXIT(err); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 743 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 744 | for (i = 0; i < gpu_count; i++) { |
| 745 | app_gpu_init(&gpus[i], i, objs[i]); |
| 746 | app_gpu_dump(&gpus[i]); |
| 747 | printf("\n\n"); |
| 748 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 749 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 750 | for (i = 0; i < gpu_count; i++) |
| 751 | app_gpu_destroy(&gpus[i]); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 752 | |
Courtney Goeltzenleuchter | 3c1ccf5 | 2015-06-04 16:20:06 -0600 | [diff] [blame] | 753 | app_destroy_instance(&inst); |
Chia-I Wu | 0b9a737 | 2014-08-06 12:09:19 +0800 | [diff] [blame] | 754 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 755 | return 0; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 756 | } |
Ian Elliott | ea95f5c | 2015-04-17 21:23:34 -0600 | [diff] [blame] | 757 | |
| 758 | #ifdef _WIN32 |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 759 | |
| 760 | // Create a console window with a large scrollback size to which to send stdout. |
| 761 | // Returns true if console window was successfully created, false otherwise. |
| 762 | bool SetStdOutToNewConsole() |
| 763 | { |
| 764 | // don't do anything if we already have a console |
| 765 | if (GetStdHandle(STD_OUTPUT_HANDLE)) |
| 766 | return false; |
| 767 | |
| 768 | // allocate a console for this app |
| 769 | AllocConsole(); |
| 770 | |
| 771 | // redirect unbuffered STDOUT to the console |
| 772 | HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); |
| 773 | int fileDescriptor = _open_osfhandle((intptr_t)consoleHandle, _O_TEXT); |
| 774 | FILE *fp = _fdopen( fileDescriptor, "w" ); |
| 775 | *stdout = *fp; |
| 776 | setvbuf( stdout, NULL, _IONBF, 0 ); |
| 777 | |
| 778 | // make the console window bigger |
| 779 | CONSOLE_SCREEN_BUFFER_INFO csbi; |
| 780 | SMALL_RECT r; |
| 781 | COORD bufferSize; |
| 782 | if (!GetConsoleScreenBufferInfo(consoleHandle, &csbi)) |
| 783 | return false; |
| 784 | bufferSize.X = csbi.dwSize.X; |
| 785 | bufferSize.Y = 1000; |
| 786 | if (!SetConsoleScreenBufferSize(consoleHandle, bufferSize)) |
| 787 | return false; |
| 788 | r.Left = r.Top = 0; |
| 789 | r.Right = csbi.dwSize.X-1; |
| 790 | r.Bottom = 60; |
| 791 | if (!SetConsoleWindowInfo(consoleHandle, true, &r)) |
| 792 | return false; |
| 793 | |
| 794 | // change the console window title |
Ian Elliott | 4e19ed0 | 2015-04-28 10:52:52 -0600 | [diff] [blame] | 795 | if (!SetConsoleTitle(TEXT(APP_SHORT_NAME))) |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 796 | return false; |
| 797 | |
| 798 | return true; |
| 799 | } |
| 800 | |
Ian Elliott | ea95f5c | 2015-04-17 21:23:34 -0600 | [diff] [blame] | 801 | int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nCmdShow) |
| 802 | { |
| 803 | char *argv = pCmdLine; |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 804 | consoleCreated = SetStdOutToNewConsole(); |
Ian Elliott | ea95f5c | 2015-04-17 21:23:34 -0600 | [diff] [blame] | 805 | main(1, &argv); |
| 806 | fflush(stdout); |
David Pinedo | 18fb923 | 2015-04-21 14:45:16 -0600 | [diff] [blame] | 807 | if (consoleCreated) |
| 808 | Sleep(INFINITE); |
Ian Elliott | ea95f5c | 2015-04-17 21:23:34 -0600 | [diff] [blame] | 809 | } |
| 810 | #endif |