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 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 30 | #include <vulkan.h> |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 31 | |
| 32 | #define ERR(err) printf("%s:%d: failed with %s\n", \ |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 33 | __FILE__, __LINE__, vk_result_string(err)); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 34 | |
| 35 | #define ERR_EXIT(err) do { ERR(err); exit(-1); } while (0) |
| 36 | |
| 37 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 38 | |
| 39 | #define MAX_GPUS 8 |
| 40 | |
| 41 | #define MAX_QUEUE_TYPES 5 |
| 42 | |
| 43 | struct app_gpu; |
| 44 | |
| 45 | struct app_dev { |
| 46 | struct app_gpu *gpu; /* point back to the GPU */ |
| 47 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 48 | VK_DEVICE obj; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 49 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 50 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 51 | VK_FORMAT_PROPERTIES format_props[VK_NUM_FMT]; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | struct app_gpu { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 55 | uint32_t id; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 56 | VK_PHYSICAL_GPU obj; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 57 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 58 | VK_PHYSICAL_GPU_PROPERTIES props; |
| 59 | VK_PHYSICAL_GPU_PERFORMANCE perf; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 60 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 61 | uint32_t queue_count; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 62 | VK_PHYSICAL_GPU_QUEUE_PROPERTIES *queue_props; |
| 63 | VK_DEVICE_QUEUE_CREATE_INFO *queue_reqs; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 64 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 65 | VK_PHYSICAL_GPU_MEMORY_PROPERTIES memory_props; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 66 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 67 | uint32_t extension_count; |
Ian Elliott | aae1a57 | 2015-02-04 16:48:37 -0700 | [diff] [blame] | 68 | char **extensions; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 69 | |
| 70 | struct app_dev dev; |
| 71 | }; |
| 72 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 73 | static const char *vk_result_string(VK_RESULT err) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 74 | { |
| 75 | switch (err) { |
| 76 | #define STR(r) case r: return #r |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 77 | STR(VK_SUCCESS); |
| 78 | STR(VK_UNSUPPORTED); |
| 79 | STR(VK_NOT_READY); |
| 80 | STR(VK_TIMEOUT); |
| 81 | STR(VK_EVENT_SET); |
| 82 | STR(VK_EVENT_RESET); |
| 83 | STR(VK_ERROR_UNKNOWN); |
| 84 | STR(VK_ERROR_UNAVAILABLE); |
| 85 | STR(VK_ERROR_INITIALIZATION_FAILED); |
| 86 | STR(VK_ERROR_OUT_OF_MEMORY); |
| 87 | STR(VK_ERROR_OUT_OF_GPU_MEMORY); |
| 88 | STR(VK_ERROR_DEVICE_ALREADY_CREATED); |
| 89 | STR(VK_ERROR_DEVICE_LOST); |
| 90 | STR(VK_ERROR_INVALID_POINTER); |
| 91 | STR(VK_ERROR_INVALID_VALUE); |
| 92 | STR(VK_ERROR_INVALID_HANDLE); |
| 93 | STR(VK_ERROR_INVALID_ORDINAL); |
| 94 | STR(VK_ERROR_INVALID_MEMORY_SIZE); |
| 95 | STR(VK_ERROR_INVALID_EXTENSION); |
| 96 | STR(VK_ERROR_INVALID_FLAGS); |
| 97 | STR(VK_ERROR_INVALID_ALIGNMENT); |
| 98 | STR(VK_ERROR_INVALID_FORMAT); |
| 99 | STR(VK_ERROR_INVALID_IMAGE); |
| 100 | STR(VK_ERROR_INVALID_DESCRIPTOR_SET_DATA); |
| 101 | STR(VK_ERROR_INVALID_QUEUE_TYPE); |
| 102 | STR(VK_ERROR_INVALID_OBJECT_TYPE); |
| 103 | STR(VK_ERROR_UNSUPPORTED_SHADER_IL_VERSION); |
| 104 | STR(VK_ERROR_BAD_SHADER_CODE); |
| 105 | STR(VK_ERROR_BAD_PIPELINE_DATA); |
| 106 | STR(VK_ERROR_TOO_MANY_MEMORY_REFERENCES); |
| 107 | STR(VK_ERROR_NOT_MAPPABLE); |
| 108 | STR(VK_ERROR_MEMORY_MAP_FAILED); |
| 109 | STR(VK_ERROR_MEMORY_UNMAP_FAILED); |
| 110 | STR(VK_ERROR_INCOMPATIBLE_DEVICE); |
| 111 | STR(VK_ERROR_INCOMPATIBLE_DRIVER); |
| 112 | STR(VK_ERROR_INCOMPLETE_COMMAND_BUFFER); |
| 113 | STR(VK_ERROR_BUILDING_COMMAND_BUFFER); |
| 114 | STR(VK_ERROR_MEMORY_NOT_BOUND); |
| 115 | STR(VK_ERROR_INCOMPATIBLE_QUEUE); |
| 116 | STR(VK_ERROR_NOT_SHAREABLE); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 117 | #undef STR |
| 118 | default: return "UNKNOWN_RESULT"; |
| 119 | } |
| 120 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 121 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 122 | static const char *vk_gpu_type_string(VK_PHYSICAL_GPU_TYPE type) |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 123 | { |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 124 | switch (type) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 125 | #define STR(r) case VK_GPU_TYPE_ ##r: return #r |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 126 | STR(OTHER); |
| 127 | STR(INTEGRATED); |
| 128 | STR(DISCRETE); |
| 129 | STR(VIRTUAL); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 130 | #undef STR |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 131 | default: return "UNKNOWN_GPU"; |
| 132 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 133 | } |
| 134 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 135 | static const char *vk_format_string(VK_FORMAT fmt) |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 136 | { |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 137 | switch (fmt) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 138 | #define STR(r) case VK_FMT_ ##r: return #r |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 139 | STR(UNDEFINED); |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 140 | STR(R4G4_UNORM); |
| 141 | STR(R4G4_USCALED); |
| 142 | STR(R4G4B4A4_UNORM); |
| 143 | STR(R4G4B4A4_USCALED); |
| 144 | STR(R5G6B5_UNORM); |
| 145 | STR(R5G6B5_USCALED); |
| 146 | STR(R5G5B5A1_UNORM); |
| 147 | STR(R5G5B5A1_USCALED); |
| 148 | STR(R8_UNORM); |
| 149 | STR(R8_SNORM); |
| 150 | STR(R8_USCALED); |
| 151 | STR(R8_SSCALED); |
| 152 | STR(R8_UINT); |
| 153 | STR(R8_SINT); |
| 154 | STR(R8_SRGB); |
| 155 | STR(R8G8_UNORM); |
| 156 | STR(R8G8_SNORM); |
| 157 | STR(R8G8_USCALED); |
| 158 | STR(R8G8_SSCALED); |
| 159 | STR(R8G8_UINT); |
| 160 | STR(R8G8_SINT); |
| 161 | STR(R8G8_SRGB); |
| 162 | STR(R8G8B8_UNORM); |
| 163 | STR(R8G8B8_SNORM); |
| 164 | STR(R8G8B8_USCALED); |
| 165 | STR(R8G8B8_SSCALED); |
| 166 | STR(R8G8B8_UINT); |
| 167 | STR(R8G8B8_SINT); |
| 168 | STR(R8G8B8_SRGB); |
| 169 | STR(R8G8B8A8_UNORM); |
| 170 | STR(R8G8B8A8_SNORM); |
| 171 | STR(R8G8B8A8_USCALED); |
| 172 | STR(R8G8B8A8_SSCALED); |
| 173 | STR(R8G8B8A8_UINT); |
| 174 | STR(R8G8B8A8_SINT); |
| 175 | STR(R8G8B8A8_SRGB); |
| 176 | STR(R10G10B10A2_UNORM); |
| 177 | STR(R10G10B10A2_SNORM); |
| 178 | STR(R10G10B10A2_USCALED); |
| 179 | STR(R10G10B10A2_SSCALED); |
| 180 | STR(R10G10B10A2_UINT); |
| 181 | STR(R10G10B10A2_SINT); |
| 182 | STR(R16_UNORM); |
| 183 | STR(R16_SNORM); |
| 184 | STR(R16_USCALED); |
| 185 | STR(R16_SSCALED); |
| 186 | STR(R16_UINT); |
| 187 | STR(R16_SINT); |
| 188 | STR(R16_SFLOAT); |
| 189 | STR(R16G16_UNORM); |
| 190 | STR(R16G16_SNORM); |
| 191 | STR(R16G16_USCALED); |
| 192 | STR(R16G16_SSCALED); |
| 193 | STR(R16G16_UINT); |
| 194 | STR(R16G16_SINT); |
| 195 | STR(R16G16_SFLOAT); |
| 196 | STR(R16G16B16_UNORM); |
| 197 | STR(R16G16B16_SNORM); |
| 198 | STR(R16G16B16_USCALED); |
| 199 | STR(R16G16B16_SSCALED); |
| 200 | STR(R16G16B16_UINT); |
| 201 | STR(R16G16B16_SINT); |
| 202 | STR(R16G16B16_SFLOAT); |
| 203 | STR(R16G16B16A16_UNORM); |
| 204 | STR(R16G16B16A16_SNORM); |
| 205 | STR(R16G16B16A16_USCALED); |
| 206 | STR(R16G16B16A16_SSCALED); |
| 207 | STR(R16G16B16A16_UINT); |
| 208 | STR(R16G16B16A16_SINT); |
| 209 | STR(R16G16B16A16_SFLOAT); |
| 210 | STR(R32_UINT); |
| 211 | STR(R32_SINT); |
| 212 | STR(R32_SFLOAT); |
| 213 | STR(R32G32_UINT); |
| 214 | STR(R32G32_SINT); |
| 215 | STR(R32G32_SFLOAT); |
| 216 | STR(R32G32B32_UINT); |
| 217 | STR(R32G32B32_SINT); |
| 218 | STR(R32G32B32_SFLOAT); |
| 219 | STR(R32G32B32A32_UINT); |
| 220 | STR(R32G32B32A32_SINT); |
| 221 | STR(R32G32B32A32_SFLOAT); |
| 222 | STR(R64_SFLOAT); |
| 223 | STR(R64G64_SFLOAT); |
| 224 | STR(R64G64B64_SFLOAT); |
| 225 | STR(R64G64B64A64_SFLOAT); |
| 226 | STR(R11G11B10_UFLOAT); |
| 227 | STR(R9G9B9E5_UFLOAT); |
| 228 | STR(D16_UNORM); |
| 229 | STR(D24_UNORM); |
| 230 | STR(D32_SFLOAT); |
| 231 | STR(S8_UINT); |
| 232 | STR(D16_UNORM_S8_UINT); |
| 233 | STR(D24_UNORM_S8_UINT); |
| 234 | STR(D32_SFLOAT_S8_UINT); |
Courtney Goeltzenleuchter | fe8a2e1 | 2015-03-03 11:30:36 -0700 | [diff] [blame] | 235 | STR(BC1_RGB_UNORM); |
| 236 | STR(BC1_RGB_SRGB); |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 237 | STR(BC2_UNORM); |
| 238 | STR(BC2_SRGB); |
| 239 | STR(BC3_UNORM); |
| 240 | STR(BC3_SRGB); |
| 241 | STR(BC4_UNORM); |
| 242 | STR(BC4_SNORM); |
| 243 | STR(BC5_UNORM); |
| 244 | STR(BC5_SNORM); |
| 245 | STR(BC6H_UFLOAT); |
| 246 | STR(BC6H_SFLOAT); |
| 247 | STR(BC7_UNORM); |
| 248 | STR(BC7_SRGB); |
| 249 | STR(ETC2_R8G8B8_UNORM); |
| 250 | STR(ETC2_R8G8B8A1_UNORM); |
| 251 | STR(ETC2_R8G8B8A8_UNORM); |
| 252 | STR(EAC_R11_UNORM); |
| 253 | STR(EAC_R11_SNORM); |
| 254 | STR(EAC_R11G11_UNORM); |
| 255 | STR(EAC_R11G11_SNORM); |
| 256 | STR(ASTC_4x4_UNORM); |
| 257 | STR(ASTC_4x4_SRGB); |
Courtney Goeltzenleuchter | fe8a2e1 | 2015-03-03 11:30:36 -0700 | [diff] [blame] | 258 | STR(ASTC_5x4_UNORM); |
| 259 | STR(ASTC_5x4_SRGB); |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 260 | STR(ASTC_5x5_UNORM); |
| 261 | STR(ASTC_5x5_SRGB); |
| 262 | STR(ASTC_6x5_UNORM); |
| 263 | STR(ASTC_6x5_SRGB); |
| 264 | STR(ASTC_6x6_UNORM); |
| 265 | STR(ASTC_6x6_SRGB); |
| 266 | STR(ASTC_8x5_UNORM); |
| 267 | STR(ASTC_8x5_SRGB); |
| 268 | STR(ASTC_8x6_UNORM); |
| 269 | STR(ASTC_8x6_SRGB); |
| 270 | STR(ASTC_8x8_UNORM); |
| 271 | STR(ASTC_8x8_SRGB); |
| 272 | STR(ASTC_10x5_UNORM); |
| 273 | STR(ASTC_10x5_SRGB); |
| 274 | STR(ASTC_10x6_UNORM); |
| 275 | STR(ASTC_10x6_SRGB); |
| 276 | STR(ASTC_10x8_UNORM); |
| 277 | STR(ASTC_10x8_SRGB); |
| 278 | STR(ASTC_10x10_UNORM); |
| 279 | STR(ASTC_10x10_SRGB); |
| 280 | STR(ASTC_12x10_UNORM); |
| 281 | STR(ASTC_12x10_SRGB); |
| 282 | STR(ASTC_12x12_UNORM); |
| 283 | STR(ASTC_12x12_SRGB); |
| 284 | STR(B5G6R5_UNORM); |
| 285 | STR(B5G6R5_USCALED); |
| 286 | STR(B8G8R8_UNORM); |
| 287 | STR(B8G8R8_SNORM); |
| 288 | STR(B8G8R8_USCALED); |
| 289 | STR(B8G8R8_SSCALED); |
| 290 | STR(B8G8R8_UINT); |
| 291 | STR(B8G8R8_SINT); |
| 292 | STR(B8G8R8_SRGB); |
| 293 | STR(B8G8R8A8_UNORM); |
| 294 | STR(B8G8R8A8_SNORM); |
| 295 | STR(B8G8R8A8_USCALED); |
| 296 | STR(B8G8R8A8_SSCALED); |
| 297 | STR(B8G8R8A8_UINT); |
| 298 | STR(B8G8R8A8_SINT); |
| 299 | STR(B8G8R8A8_SRGB); |
| 300 | STR(B10G10R10A2_UNORM); |
| 301 | STR(B10G10R10A2_SNORM); |
| 302 | STR(B10G10R10A2_USCALED); |
| 303 | STR(B10G10R10A2_SSCALED); |
| 304 | STR(B10G10R10A2_UINT); |
| 305 | STR(B10G10R10A2_SINT); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 306 | #undef STR |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 307 | default: return "UNKNOWN_FORMAT"; |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 308 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 309 | } |
| 310 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 311 | static void app_dev_init_formats(struct app_dev *dev) |
| 312 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 313 | VK_FORMAT f; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 314 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 315 | for (f = 0; f < VK_NUM_FMT; f++) { |
| 316 | const VK_FORMAT fmt = f; |
| 317 | VK_RESULT err; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 318 | size_t size = sizeof(dev->format_props[f]); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 319 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 320 | err = vkGetFormatInfo(dev->obj, fmt, |
| 321 | VK_INFO_TYPE_FORMAT_PROPERTIES, |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 322 | &size, &dev->format_props[f]); |
| 323 | if (err) { |
| 324 | memset(&dev->format_props[f], 0, |
| 325 | sizeof(dev->format_props[f])); |
| 326 | } |
| 327 | else if (size != sizeof(dev->format_props[f])) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 328 | ERR_EXIT(VK_ERROR_UNKNOWN); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | static void app_dev_init(struct app_dev *dev, struct app_gpu *gpu) |
| 334 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 335 | VK_DEVICE_CREATE_INFO info = { |
| 336 | .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 337 | .pNext = NULL, |
| 338 | .queueRecordCount = 0, |
| 339 | .pRequestedQueues = NULL, |
| 340 | .extensionCount = 0, |
| 341 | .ppEnabledExtensionNames = NULL, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 342 | .maxValidationLevel = VK_VALIDATION_LEVEL_END_RANGE, |
| 343 | .flags = VK_DEVICE_CREATE_VALIDATION_BIT, |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 344 | }; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 345 | VK_RESULT err; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 346 | |
| 347 | /* request all queues */ |
| 348 | info.queueRecordCount = gpu->queue_count; |
| 349 | info.pRequestedQueues = gpu->queue_reqs; |
| 350 | |
| 351 | /* enable all extensions */ |
| 352 | info.extensionCount = gpu->extension_count; |
Ian Elliott | 092ee85 | 2015-02-11 17:36:23 -0700 | [diff] [blame] | 353 | info.ppEnabledExtensionNames = (const char*const*) gpu->extensions; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 354 | dev->gpu = gpu; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 355 | err = vkCreateDevice(gpu->obj, &info, &dev->obj); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 356 | if (err) |
| 357 | ERR_EXIT(err); |
| 358 | |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static void app_dev_destroy(struct app_dev *dev) |
| 362 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 363 | vkDestroyDevice(dev->obj); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | static void app_gpu_init_extensions(struct app_gpu *gpu) |
| 367 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 368 | VK_RESULT err; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 369 | uint32_t i; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 370 | |
Ian Elliott | aae1a57 | 2015-02-04 16:48:37 -0700 | [diff] [blame] | 371 | static char *known_extensions[] = { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 372 | "VK_WSI_X11", |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 373 | }; |
| 374 | |
| 375 | for (i = 0; i < ARRAY_SIZE(known_extensions); i++) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 376 | err = vkGetExtensionSupport(gpu->obj, known_extensions[i]); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 377 | if (!err) |
| 378 | gpu->extension_count++; |
| 379 | } |
| 380 | |
| 381 | gpu->extensions = |
| 382 | malloc(sizeof(gpu->extensions[0]) * gpu->extension_count); |
| 383 | if (!gpu->extensions) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 384 | ERR_EXIT(VK_ERROR_OUT_OF_MEMORY); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 385 | |
| 386 | gpu->extension_count = 0; |
| 387 | for (i = 0; i < ARRAY_SIZE(known_extensions); i++) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 388 | err = vkGetExtensionSupport(gpu->obj, known_extensions[i]); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 389 | if (!err) |
| 390 | gpu->extensions[gpu->extension_count++] = known_extensions[i]; |
| 391 | } |
| 392 | } |
| 393 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 394 | static void app_gpu_init(struct app_gpu *gpu, uint32_t id, VK_PHYSICAL_GPU obj) |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 395 | { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 396 | size_t size; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 397 | VK_RESULT err; |
Ian Elliott | aae1a57 | 2015-02-04 16:48:37 -0700 | [diff] [blame] | 398 | uint32_t i; |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 399 | |
| 400 | memset(gpu, 0, sizeof(*gpu)); |
| 401 | |
| 402 | gpu->id = id; |
| 403 | gpu->obj = obj; |
| 404 | size = sizeof(gpu->props); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 405 | err = vkGetGpuInfo(gpu->obj, |
| 406 | VK_INFO_TYPE_PHYSICAL_GPU_PROPERTIES, |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 407 | &size, &gpu->props); |
| 408 | if (err || size != sizeof(gpu->props)) |
| 409 | ERR_EXIT(err); |
| 410 | |
| 411 | size = sizeof(gpu->perf); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 412 | err = vkGetGpuInfo(gpu->obj, |
| 413 | VK_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE, |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 414 | &size, &gpu->perf); |
| 415 | if (err || size != sizeof(gpu->perf)) |
| 416 | ERR_EXIT(err); |
| 417 | |
| 418 | /* get queue count */ |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 419 | err = vkGetGpuInfo(gpu->obj, |
| 420 | VK_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES, |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 421 | &size, NULL); |
| 422 | if (err || size % sizeof(gpu->queue_props[0])) |
| 423 | ERR_EXIT(err); |
Ian Elliott | aae1a57 | 2015-02-04 16:48:37 -0700 | [diff] [blame] | 424 | gpu->queue_count = (uint32_t) (size / sizeof(gpu->queue_props[0])); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 425 | |
| 426 | gpu->queue_props = |
| 427 | malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count); |
| 428 | size = sizeof(gpu->queue_props[0]) * gpu->queue_count; |
| 429 | if (!gpu->queue_props) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 430 | ERR_EXIT(VK_ERROR_OUT_OF_MEMORY); |
| 431 | err = vkGetGpuInfo(gpu->obj, |
| 432 | VK_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES, |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 433 | &size, gpu->queue_props); |
| 434 | if (err || size != sizeof(gpu->queue_props[0]) * gpu->queue_count) |
| 435 | ERR_EXIT(err); |
| 436 | |
| 437 | /* set up queue requests */ |
| 438 | size = sizeof(*gpu->queue_reqs) * gpu->queue_count; |
| 439 | gpu->queue_reqs = malloc(sizeof(*gpu->queue_reqs) * gpu->queue_count); |
| 440 | if (!gpu->queue_reqs) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 441 | ERR_EXIT(VK_ERROR_OUT_OF_MEMORY); |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 442 | for (i = 0; i < gpu->queue_count; i++) { |
| 443 | gpu->queue_reqs[i].queueNodeIndex = i; |
| 444 | gpu->queue_reqs[i].queueCount = gpu->queue_props[i].queueCount; |
| 445 | } |
| 446 | |
| 447 | size = sizeof(gpu->memory_props); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 448 | err = vkGetGpuInfo(gpu->obj, |
| 449 | VK_INFO_TYPE_PHYSICAL_GPU_MEMORY_PROPERTIES, |
Chia-I Wu | 46c29dd | 2014-12-02 21:09:20 +0800 | [diff] [blame] | 450 | &size, &gpu->memory_props); |
| 451 | if (err || size != sizeof(gpu->memory_props)) |
| 452 | ERR_EXIT(err); |
| 453 | |
| 454 | app_gpu_init_extensions(gpu); |
| 455 | app_dev_init(&gpu->dev, gpu); |
| 456 | app_dev_init_formats(&gpu->dev); |
| 457 | } |
| 458 | |
| 459 | static void app_gpu_destroy(struct app_gpu *gpu) |
| 460 | { |
| 461 | app_dev_destroy(&gpu->dev); |
| 462 | free(gpu->extensions); |
| 463 | free(gpu->queue_reqs); |
| 464 | free(gpu->queue_props); |
| 465 | } |
| 466 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 467 | static void app_dev_dump_format_props(const struct app_dev *dev, VK_FORMAT fmt) |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 468 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 469 | const VK_FORMAT_PROPERTIES *props = &dev->format_props[fmt]; |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 470 | struct { |
| 471 | const char *name; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 472 | VK_FLAGS flags; |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 473 | } tilings[2]; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 474 | uint32_t i; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 475 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 476 | if (!props->linearTilingFeatures && !props->optimalTilingFeatures) |
| 477 | return; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 478 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 479 | tilings[0].name = "linear"; |
| 480 | tilings[0].flags = props->linearTilingFeatures; |
| 481 | tilings[1].name = "optimal"; |
| 482 | tilings[1].flags = props->optimalTilingFeatures; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 483 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 484 | printf("FORMAT_%s\n", vk_format_string(fmt)); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 485 | for (i = 0; i < ARRAY_SIZE(tilings); i++) { |
| 486 | if (!tilings[i].flags) |
| 487 | continue; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 488 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 489 | printf("\t%s tiling image =%s%s%s\n", tilings[i].name, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 490 | (tilings[i].flags & VK_FORMAT_IMAGE_SHADER_READ_BIT) ? " read" : "", |
| 491 | (tilings[i].flags & VK_FORMAT_IMAGE_SHADER_WRITE_BIT) ? " write" : "", |
| 492 | (tilings[i].flags & VK_FORMAT_IMAGE_COPY_BIT) ? " copy" : ""); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 493 | printf("\t%s tiling memory =%s\n", tilings[i].name, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 494 | (tilings[i].flags & VK_FORMAT_MEMORY_SHADER_ACCESS_BIT) ? " access" : ""); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 495 | printf("\t%s tiling attachment =%s%s%s%s%s\n", tilings[i].name, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 496 | (tilings[i].flags & VK_FORMAT_COLOR_ATTACHMENT_WRITE_BIT) ? " color" : "", |
| 497 | (tilings[i].flags & VK_FORMAT_COLOR_ATTACHMENT_BLEND_BIT) ? " blend" : "", |
| 498 | (tilings[i].flags & VK_FORMAT_DEPTH_ATTACHMENT_BIT) ? " depth" : "", |
| 499 | (tilings[i].flags & VK_FORMAT_STENCIL_ATTACHMENT_BIT) ? " stencil" : "", |
| 500 | (tilings[i].flags & VK_FORMAT_MSAA_ATTACHMENT_BIT) ? " msaa" : ""); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 501 | printf("\t%s tiling conversion = %u\n", tilings[i].name, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 502 | (bool) (tilings[i].flags & VK_FORMAT_CONVERSION_BIT)); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 503 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 504 | } |
| 505 | |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 506 | |
| 507 | static void |
| 508 | app_dev_dump(const struct app_dev *dev) |
| 509 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 510 | VK_FORMAT fmt; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 511 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 512 | for (fmt = 0; fmt < VK_NUM_FMT; fmt++) { |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 513 | app_dev_dump_format_props(dev, fmt); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 514 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static void app_gpu_dump_multi_compat(const struct app_gpu *gpu, const struct app_gpu *other, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 518 | const VK_GPU_COMPATIBILITY_INFO *info) |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 519 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 520 | printf("VK_GPU_COMPATIBILITY_INFO[GPU%d]\n", other->id); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 521 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 522 | #define TEST(info, b) printf(#b " = %u\n", (bool) (info->compatibilityFlags & VK_GPU_COMPAT_ ##b## _BIT)) |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 523 | TEST(info, ASIC_FEATURES); |
| 524 | TEST(info, IQ_MATCH); |
| 525 | TEST(info, PEER_TRANSFER); |
| 526 | TEST(info, SHARED_MEMORY); |
| 527 | TEST(info, SHARED_SYNC); |
| 528 | TEST(info, SHARED_GPU0_DISPLAY); |
| 529 | TEST(info, SHARED_GPU1_DISPLAY); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 530 | #undef TEST |
| 531 | } |
| 532 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 533 | static void app_gpu_multi_compat(struct app_gpu *gpus, uint32_t gpu_count) |
Courtney Goeltzenleuchter | d183e71 | 2014-08-06 16:12:02 -0600 | [diff] [blame] | 534 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 535 | VK_RESULT err; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 536 | uint32_t i, j; |
Courtney Goeltzenleuchter | d183e71 | 2014-08-06 16:12:02 -0600 | [diff] [blame] | 537 | |
| 538 | for (i = 0; i < gpu_count; i++) { |
| 539 | for (j = 0; j < gpu_count; j++) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 540 | VK_GPU_COMPATIBILITY_INFO info; |
Courtney Goeltzenleuchter | d183e71 | 2014-08-06 16:12:02 -0600 | [diff] [blame] | 541 | |
| 542 | if (i == j) |
| 543 | continue; |
| 544 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 545 | err = vkGetMultiGpuCompatibility(gpus[i].obj, |
Courtney Goeltzenleuchter | d183e71 | 2014-08-06 16:12:02 -0600 | [diff] [blame] | 546 | gpus[j].obj, &info); |
| 547 | if (err) |
| 548 | ERR_EXIT(err); |
| 549 | |
| 550 | app_gpu_dump_multi_compat(&gpus[i], &gpus[j], &info); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 555 | static void app_gpu_dump_props(const struct app_gpu *gpu) |
| 556 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 557 | const VK_PHYSICAL_GPU_PROPERTIES *props = &gpu->props; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 558 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 559 | printf("VK_PHYSICAL_GPU_PROPERTIES\n"); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 560 | printf("\tapiVersion = %u\n", props->apiVersion); |
| 561 | printf("\tdriverVersion = %u\n", props->driverVersion); |
| 562 | printf("\tvendorId = 0x%04x\n", props->vendorId); |
| 563 | printf("\tdeviceId = 0x%04x\n", props->deviceId); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 564 | printf("\tgpuType = %s\n", vk_gpu_type_string(props->gpuType)); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 565 | printf("\tgpuName = %s\n", props->gpuName); |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 566 | printf("\tmaxInlineMemoryUpdateSize = %zu\n", props->maxInlineMemoryUpdateSize); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 567 | printf("\tmaxBoundDescriptorSets = %u\n", props->maxBoundDescriptorSets); |
| 568 | printf("\tmaxThreadGroupSize = %u\n", props->maxThreadGroupSize); |
| 569 | printf("\ttimestampFrequency = %lu\n", props->timestampFrequency); |
| 570 | printf("\tmultiColorAttachmentClears = %u\n", props->multiColorAttachmentClears); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | static void app_gpu_dump_perf(const struct app_gpu *gpu) |
| 574 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 575 | const VK_PHYSICAL_GPU_PERFORMANCE *perf = &gpu->perf; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 576 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 577 | printf("VK_PHYSICAL_GPU_PERFORMANCE\n"); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 578 | printf("\tmaxGpuClock = %f\n", perf->maxGpuClock); |
| 579 | printf("\taluPerClock = %f\n", perf->aluPerClock); |
| 580 | printf("\ttexPerClock = %f\n", perf->texPerClock); |
| 581 | printf("\tprimsPerClock = %f\n", perf->primsPerClock); |
| 582 | printf("\tpixelsPerClock = %f\n", perf->pixelsPerClock); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 583 | } |
| 584 | |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 585 | static void app_gpu_dump_extensions(const struct app_gpu *gpu) |
| 586 | { |
Ian Elliott | aae1a57 | 2015-02-04 16:48:37 -0700 | [diff] [blame] | 587 | uint32_t i; |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 588 | printf("Extensions"); |
| 589 | printf("\tcount = %d\n", gpu->extension_count); |
| 590 | printf("\t"); |
| 591 | for (i=0; i< gpu->extension_count; i++) { |
| 592 | if (i>0) |
| 593 | printf(", "); // separator between extension names |
| 594 | printf("%s", gpu->extensions[i]); |
| 595 | } |
| 596 | printf("\n"); |
| 597 | } |
| 598 | |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 599 | 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] | 600 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 601 | const VK_PHYSICAL_GPU_QUEUE_PROPERTIES *props = &gpu->queue_props[id]; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 602 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 603 | printf("VK_PHYSICAL_GPU_QUEUE_PROPERTIES[%d]\n", id); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 604 | printf("\tqueueFlags = %c%c%c%c\n", |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 605 | (props->queueFlags & VK_QUEUE_GRAPHICS_BIT) ? 'G' : '.', |
| 606 | (props->queueFlags & VK_QUEUE_COMPUTE_BIT) ? 'C' : '.', |
| 607 | (props->queueFlags & VK_QUEUE_DMA_BIT) ? 'D' : '.', |
| 608 | (props->queueFlags & VK_QUEUE_EXTENDED_BIT) ? 'X' : '.'); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 609 | printf("\tqueueCount = %u\n", props->queueCount); |
| 610 | printf("\tmaxAtomicCounters = %u\n", props->maxAtomicCounters); |
| 611 | printf("\tsupportsTimestamps = %u\n", props->supportsTimestamps); |
Courtney Goeltzenleuchter | e16aa8e | 2015-04-02 14:22:12 -0600 | [diff] [blame] | 612 | printf("\tmaxMemReferences = %u\n", props->maxMemReferences); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | static void app_gpu_dump_memory_props(const struct app_gpu *gpu) |
| 616 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 617 | const VK_PHYSICAL_GPU_MEMORY_PROPERTIES *props = &gpu->memory_props; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 618 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 619 | printf("VK_PHYSICAL_GPU_MEMORY_PROPERTIES\n"); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 620 | printf("\tsupportsMigration = %u\n", props->supportsMigration); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 621 | printf("\tsupportsPinning = %u\n", props->supportsPinning); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | static void app_gpu_dump(const struct app_gpu *gpu) |
| 625 | { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 626 | uint32_t i; |
Chia-I Wu | f5c46f4 | 2014-08-05 15:33:40 +0800 | [diff] [blame] | 627 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 628 | printf("GPU%u\n", gpu->id); |
| 629 | app_gpu_dump_props(gpu); |
| 630 | printf("\n"); |
Courtney Goeltzenleuchter | ff87c82 | 2014-10-03 18:05:10 -0600 | [diff] [blame] | 631 | app_gpu_dump_extensions(gpu); |
| 632 | printf("\n"); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 633 | app_gpu_dump_perf(gpu); |
| 634 | printf("\n"); |
| 635 | for (i = 0; i < gpu->queue_count; i++) { |
| 636 | app_gpu_dump_queue_props(gpu, i); |
| 637 | printf("\n"); |
| 638 | } |
| 639 | app_gpu_dump_memory_props(gpu); |
| 640 | printf("\n"); |
| 641 | app_dev_dump(&gpu->dev); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 642 | } |
| 643 | |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 644 | int main(int argc, char **argv) |
| 645 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 646 | static const VK_APPLICATION_INFO app_info = { |
| 647 | .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 648 | .pNext = NULL, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 649 | .pAppName = "vkinfo", |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 650 | .appVersion = 1, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 651 | .pEngineName = "vkinfo", |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 652 | .engineVersion = 1, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 653 | .apiVersion = VK_API_VERSION, |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 654 | }; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 655 | static const VK_INSTANCE_CREATE_INFO inst_info = { |
| 656 | .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 657 | .pNext = NULL, |
| 658 | .pAppInfo = &app_info, |
| 659 | .pAllocCb = NULL, |
| 660 | .extensionCount = 0, |
| 661 | .ppEnabledExtensionNames = NULL, |
| 662 | }; |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 663 | struct app_gpu gpus[MAX_GPUS]; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 664 | VK_PHYSICAL_GPU objs[MAX_GPUS]; |
| 665 | VK_INSTANCE inst; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 666 | uint32_t gpu_count, i; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 667 | VK_RESULT err; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 668 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 669 | err = vkCreateInstance(&inst_info, &inst); |
| 670 | if (err == VK_ERROR_INCOMPATIBLE_DRIVER) { |
Ian Elliott | dfe55f7 | 2015-04-03 15:24:55 -0600 | [diff] [blame] | 671 | printf("Cannot find a compatible Vulkan installable client driver " |
| 672 | "(ICD).\nExiting ...\n"); |
| 673 | fflush(stdout); |
| 674 | exit(1); |
| 675 | } else if (err) { |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 676 | |
Jon Ashburn | 92e8013 | 2015-01-29 15:47:01 -0700 | [diff] [blame] | 677 | ERR_EXIT(err); |
Ian Elliott | dfe55f7 | 2015-04-03 15:24:55 -0600 | [diff] [blame] | 678 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 679 | err = vkEnumerateGpus(inst, MAX_GPUS, &gpu_count, objs); |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 680 | if (err) |
| 681 | ERR_EXIT(err); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 682 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 683 | for (i = 0; i < gpu_count; i++) { |
| 684 | app_gpu_init(&gpus[i], i, objs[i]); |
| 685 | app_gpu_dump(&gpus[i]); |
| 686 | printf("\n\n"); |
| 687 | } |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 688 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 689 | app_gpu_multi_compat(gpus, gpu_count); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 690 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 691 | for (i = 0; i < gpu_count; i++) |
| 692 | app_gpu_destroy(&gpus[i]); |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 693 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 694 | vkDestroyInstance(inst); |
Chia-I Wu | 0b9a737 | 2014-08-06 12:09:19 +0800 | [diff] [blame] | 695 | |
Chia-I Wu | 190ebdc | 2014-08-06 12:04:13 +0800 | [diff] [blame] | 696 | return 0; |
Chia-I Wu | d4bae36 | 2014-07-29 11:15:00 +0800 | [diff] [blame] | 697 | } |