vulkaninfo.c revision 22e811615165a8a8254529d3ffa3449d0bcadc58
1/* 2 * Vulkan 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 */ 24#include <stdlib.h> 25#include <stdio.h> 26#include <stdbool.h> 27#include <string.h> 28#include <assert.h> 29 30#ifdef _WIN32 31#include <Windows.h> 32#include <fcntl.h> 33#include <io.h> 34#endif 35 36#include <vulkan.h> 37 38#define ERR(err) printf("%s:%d: failed with %s\n", \ 39 __FILE__, __LINE__, vk_result_string(err)); 40 41#ifdef _WIN32 42 43bool 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) 62 63#if defined(NDEBUG) && defined(__GNUC__) 64#define U_ASSERT_ONLY __attribute__((unused)) 65#else 66#define U_ASSERT_ONLY 67#endif 68 69#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 70 71#define MAX_GPUS 8 72 73#define MAX_QUEUE_TYPES 5 74#define APP_SHORT_NAME "vulkaninfo" 75 76struct app_gpu; 77 78struct app_dev { 79 struct app_gpu *gpu; /* point back to the GPU */ 80 81 VkDevice obj; 82 83 84 VkFormatProperties format_props[VK_NUM_FORMAT]; 85}; 86 87struct app_instance { 88 VkInstance instance; 89 uint32_t global_extension_count; 90 VkExtensionProperties *global_extensions; 91}; 92 93struct app_gpu { 94 uint32_t id; 95 VkPhysicalDevice obj; 96 97 VkPhysicalDeviceProperties props; 98 VkPhysicalDevicePerformance perf; 99 100 uint32_t queue_count; 101 VkPhysicalDeviceQueueProperties *queue_props; 102 VkDeviceQueueCreateInfo *queue_reqs; 103 104 VkPhysicalDeviceMemoryProperties memory_props; 105 106 uint32_t device_extension_count; 107 VkExtensionProperties *device_extensions; 108 109 struct app_dev dev; 110}; 111 112static const char *vk_result_string(VkResult err) 113{ 114 switch (err) { 115#define STR(r) case r: return #r 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); 125 STR(VK_ERROR_OUT_OF_HOST_MEMORY); 126 STR(VK_ERROR_OUT_OF_DEVICE_MEMORY); 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); 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); 154#undef STR 155 default: return "UNKNOWN_RESULT"; 156 } 157} 158 159static const char *vk_physical_device_type_string(VkPhysicalDeviceType type) 160{ 161 switch (type) { 162#define STR(r) case VK_PHYSICAL_DEVICE_TYPE_ ##r: return #r 163 STR(OTHER); 164 STR(INTEGRATED_GPU); 165 STR(DISCRETE_GPU); 166 STR(VIRTUAL_GPU); 167#undef STR 168 default: return "UNKNOWN_DEVICE"; 169 } 170} 171 172static const char *vk_format_string(VkFormat fmt) 173{ 174 switch (fmt) { 175#define STR(r) case VK_FORMAT_ ##r: return #r 176 STR(UNDEFINED); 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); 272 STR(BC1_RGB_UNORM); 273 STR(BC1_RGB_SRGB); 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); 295 STR(ASTC_5x4_UNORM); 296 STR(ASTC_5x4_SRGB); 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); 343#undef STR 344 default: return "UNKNOWN_FORMAT"; 345 } 346} 347 348static void app_dev_init_formats(struct app_dev *dev) 349{ 350 VkFormat f; 351 352 for (f = 0; f < VK_NUM_FORMAT; f++) { 353 const VkFormat fmt = f; 354 VkResult err; 355 356 err = vkGetPhysicalDeviceFormatInfo(dev->gpu->obj, fmt, &dev->format_props[f]); 357 if (err) { 358 memset(&dev->format_props[f], 0, 359 sizeof(dev->format_props[f])); 360 } 361 } 362} 363 364static void app_dev_init(struct app_dev *dev, struct app_gpu *gpu) 365{ 366 VkDeviceCreateInfo info = { 367 .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, 368 .pNext = NULL, 369 .queueRecordCount = 0, 370 .pRequestedQueues = NULL, 371 .extensionCount = 0, 372 .pEnabledExtensions = NULL, 373 .flags = 0, 374 }; 375 VkResult U_ASSERT_ONLY err; 376 // Extensions to enable 377 VkExtensionProperties *enable_extension_list; 378 static char *known_extensions[] = { 379 "Validation", 380 }; 381 382 uint32_t extCount; 383 err = vkGetPhysicalDeviceExtensionCount(gpu->obj, &extCount); 384 assert(!err); 385 386 enable_extension_list = malloc(sizeof(VkExtensionProperties) * extCount); 387 if (!enable_extension_list) { 388 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); 389 } 390 391 VkExtensionProperties extProp; 392 gpu->device_extension_count = 0; 393 bool32_t U_ASSERT_ONLY extFound = 0; // TODO : Need to enhance this if/when we enable multiple extensions 394 for (uint32_t i = 0; i < ARRAY_SIZE(known_extensions); i++) { 395 for (uint32_t j = 0; j < extCount; j++) { 396 err = vkGetPhysicalDeviceExtensionProperties( 397 gpu->obj, j, &extProp); 398 if (!strcmp(known_extensions[i], extProp.name)) { 399 extFound = 1; 400 memcpy(&enable_extension_list[gpu->device_extension_count], &extProp, sizeof(extProp)); 401 gpu->device_extension_count++; 402 } 403 } 404 } 405 assert(extFound); 406 407 gpu->device_extensions = enable_extension_list; 408 409 /* request all queues */ 410 info.queueRecordCount = gpu->queue_count; 411 info.pRequestedQueues = gpu->queue_reqs; 412 413 info.extensionCount = extCount; 414 info.pEnabledExtensions = enable_extension_list; 415 dev->gpu = gpu; 416 err = vkCreateDevice(gpu->obj, &info, &dev->obj); 417 if (err) 418 ERR_EXIT(err); 419 420} 421 422static void app_dev_destroy(struct app_dev *dev) 423{ 424 vkDestroyDevice(dev->obj); 425} 426 427static void app_create_instance(struct app_instance *inst) 428{ 429 const VkApplicationInfo app_info = { 430 .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, 431 .pNext = NULL, 432 .pAppName = APP_SHORT_NAME, 433 .appVersion = 1, 434 .pEngineName = APP_SHORT_NAME, 435 .engineVersion = 1, 436 .apiVersion = VK_API_VERSION, 437 }; 438 VkInstanceCreateInfo inst_info = { 439 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, 440 .pNext = NULL, 441 .pAppInfo = &app_info, 442 .pAllocCb = NULL, 443 .extensionCount = 0, 444 .pEnabledExtensions = NULL, 445 }; 446 VkResult U_ASSERT_ONLY err; 447 // Global Extensions to enable 448 static char *known_extensions[] = { 449 "VK_WSI_LunarG", 450 }; 451 452 uint32_t extCount = 0; 453 VkExtensionProperties extProp; 454 VkExtensionProperties *enable_extension_list; 455 uint32_t global_extension_count = 0; 456 457 err = vkGetGlobalExtensionCount(&extCount); 458 assert(!err); 459 460 enable_extension_list = malloc(sizeof(VkExtensionProperties) * extCount); 461 if (!enable_extension_list) { 462 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); 463 } 464 465 bool32_t U_ASSERT_ONLY extFound = 0; // TODO : Need to enhance this if/when we enable multiple extensions 466 for (uint32_t i = 0; i < ARRAY_SIZE(known_extensions); i++) { 467 for (uint32_t j = 0; j < extCount; j++) { 468 err = vkGetGlobalExtensionProperties(j, &extProp); 469 if (!strcmp(known_extensions[i], extProp.name)) { 470 extFound = 1; 471 memcpy(&enable_extension_list[global_extension_count], &extProp, sizeof(extProp)); 472 global_extension_count++; 473 } 474 } 475 } 476 assert(extFound); 477 478 inst_info.extensionCount = global_extension_count; 479 inst_info.pEnabledExtensions = enable_extension_list; 480 481 err = vkCreateInstance(&inst_info, &inst->instance); 482 if (err == VK_ERROR_INCOMPATIBLE_DRIVER) { 483 printf("Cannot create Vulkan instance.\n"); 484 ERR_EXIT(err); 485 } else if (err) { 486 ERR_EXIT(err); 487 } 488 489 inst->global_extension_count = global_extension_count; 490 inst->global_extensions = enable_extension_list; 491} 492 493static void app_destroy_instance(struct app_instance *inst) 494{ 495 free(inst->global_extensions); 496 vkDestroyInstance(inst->instance); 497} 498 499 500static void app_gpu_init(struct app_gpu *gpu, uint32_t id, VkPhysicalDevice obj) 501{ 502 VkResult err; 503 uint32_t i; 504 505 memset(gpu, 0, sizeof(*gpu)); 506 507 gpu->id = id; 508 gpu->obj = obj; 509 510 err = vkGetPhysicalDeviceProperties(gpu->obj, &gpu->props); 511 if (err) 512 ERR_EXIT(err); 513 514 err = vkGetPhysicalDevicePerformance(gpu->obj, &gpu->perf); 515 if (err) 516 ERR_EXIT(err); 517 518 /* get queue count */ 519 err = vkGetPhysicalDeviceQueueCount(gpu->obj, &gpu->queue_count); 520 if (err) 521 ERR_EXIT(err); 522 523 gpu->queue_props = 524 malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count); 525 526 if (!gpu->queue_props) 527 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); 528 err = vkGetPhysicalDeviceQueueProperties(gpu->obj, gpu->queue_count, gpu->queue_props); 529 if (err) 530 ERR_EXIT(err); 531 532 /* set up queue requests */ 533 gpu->queue_reqs = malloc(sizeof(*gpu->queue_reqs) * gpu->queue_count); 534 if (!gpu->queue_reqs) 535 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); 536 for (i = 0; i < gpu->queue_count; i++) { 537 gpu->queue_reqs[i].queueNodeIndex = i; 538 gpu->queue_reqs[i].queueCount = gpu->queue_props[i].queueCount; 539 } 540 541 err = vkGetPhysicalDeviceMemoryProperties(gpu->obj, &gpu->memory_props); 542 if (err) 543 ERR_EXIT(err); 544 545 app_dev_init(&gpu->dev, gpu); 546 app_dev_init_formats(&gpu->dev); 547} 548 549static void app_gpu_destroy(struct app_gpu *gpu) 550{ 551 app_dev_destroy(&gpu->dev); 552 free(gpu->device_extensions); 553 free(gpu->queue_reqs); 554 free(gpu->queue_props); 555} 556 557static void app_dev_dump_format_props(const struct app_dev *dev, VkFormat fmt) 558{ 559 const VkFormatProperties *props = &dev->format_props[fmt]; 560 struct { 561 const char *name; 562 VkFlags flags; 563 } tilings[2]; 564 uint32_t i; 565 566 if (!props->linearTilingFeatures && !props->optimalTilingFeatures) 567 return; 568 569 tilings[0].name = "linear"; 570 tilings[0].flags = props->linearTilingFeatures; 571 tilings[1].name = "optimal"; 572 tilings[1].flags = props->optimalTilingFeatures; 573 574 printf("FORMAT_%s\n", vk_format_string(fmt)); 575 for (i = 0; i < ARRAY_SIZE(tilings); i++) { 576 if (!tilings[i].flags) 577 continue; 578 579 printf("\t%s tiling image =%s%s%s\n", tilings[i].name, 580 (tilings[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) ? " sampled" : "", 581 (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) ? " storage" : "", 582 (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT) ? " atomic" : ""); 583 printf("\t%s tiling texel =%s%s%s\n", tilings[i].name, 584 (tilings[i].flags & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT) ? " TBO" : "", 585 (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT) ? " IBO" : "", 586 (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT) ? " atomic" : ""); 587 printf("\t%s tiling attachment =%s%s%s\n", tilings[i].name, 588 (tilings[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) ? " color" : "", 589 (tilings[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT) ? " blend" : "", 590 (tilings[i].flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) ? " depth/stencil" : ""); 591 printf("\t%s tiling vertex = %u\n", tilings[i].name, 592 (bool) (tilings[i].flags & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT)); 593 printf("\t%s tiling conversion = %u\n", tilings[i].name, 594 (bool) (tilings[i].flags & VK_FORMAT_FEATURE_CONVERSION_BIT)); 595 } 596} 597 598 599static void 600app_dev_dump(const struct app_dev *dev) 601{ 602 VkFormat fmt; 603 604 for (fmt = 0; fmt < VK_NUM_FORMAT; fmt++) { 605 app_dev_dump_format_props(dev, fmt); 606 } 607} 608 609#ifdef _WIN32 610#define PRINTF_SIZE_T_SPECIFIER "%Iu" 611#else 612#define PRINTF_SIZE_T_SPECIFIER "%zu" 613#endif 614 615static void app_gpu_dump_props(const struct app_gpu *gpu) 616{ 617 const VkPhysicalDeviceProperties *props = &gpu->props; 618 619 printf("VkPhysicalDeviceProperties\n"); 620 printf("\tapiVersion = %u\n", props->apiVersion); 621 printf("\tdriverVersion = %u\n", props->driverVersion); 622 printf("\tvendorId = 0x%04x\n", props->vendorId); 623 printf("\tdeviceId = 0x%04x\n", props->deviceId); 624 printf("\tdeviceType = %s\n", vk_physical_device_type_string(props->deviceType)); 625 printf("\tdeviceName = %s\n", props->deviceName); 626 printf("\tmaxBoundDescriptorSets = %u\n", props->maxBoundDescriptorSets); 627 printf("\tmaxThreadGroupSize = %u\n", props->maxThreadGroupSize); 628 printf("\ttimestampFrequency = %lu\n", props->timestampFrequency); 629 printf("\tmultiColorAttachmentClears = %u\n", props->multiColorAttachmentClears); 630} 631 632static void app_gpu_dump_perf(const struct app_gpu *gpu) 633{ 634 const VkPhysicalDevicePerformance *perf = &gpu->perf; 635 636 printf("VkPhysicalDevicePerformance\n"); 637 printf("\tmaxGpuClock = %f\n", perf->maxDeviceClock); 638 printf("\taluPerClock = %f\n", perf->aluPerClock); 639 printf("\ttexPerClock = %f\n", perf->texPerClock); 640 printf("\tprimsPerClock = %f\n", perf->primsPerClock); 641 printf("\tpixelsPerClock = %f\n", perf->pixelsPerClock); 642} 643 644static void app_gpu_dump_instance_extensions(const struct app_instance *inst) 645{ 646 uint32_t i; 647 printf("Extensions"); 648 printf("\tcount = %d\n", inst->global_extension_count); 649 printf("\t"); 650 for (i=0; i< inst->global_extension_count; i++) { 651 if (i>0) 652 printf(", "); // separator between extension names 653 printf("%s", inst->global_extensions[i].name); 654 } 655 printf("\n"); 656} 657 658static void app_gpu_dump_extensions(const struct app_gpu *gpu) 659{ 660 uint32_t i; 661 printf("Extensions"); 662 printf("\tcount = %d\n", gpu->device_extension_count); 663 printf("\t"); 664 for (i=0; i< gpu->device_extension_count; i++) { 665 if (i>0) 666 printf(", "); // separator between extension names 667 printf("%s(%d): %s", gpu->device_extensions[i].name, 668 gpu->device_extensions[i].version, 669 gpu->device_extensions[i].description); 670 } 671 printf("\n"); 672} 673 674static void app_gpu_dump_queue_props(const struct app_gpu *gpu, uint32_t id) 675{ 676 const VkPhysicalDeviceQueueProperties *props = &gpu->queue_props[id]; 677 678 printf("VkPhysicalDeviceQueueProperties[%d]\n", id); 679 printf("\tqueueFlags = %c%c%c%c\n", 680 (props->queueFlags & VK_QUEUE_GRAPHICS_BIT) ? 'G' : '.', 681 (props->queueFlags & VK_QUEUE_COMPUTE_BIT) ? 'C' : '.', 682 (props->queueFlags & VK_QUEUE_DMA_BIT) ? 'D' : '.', 683 (props->queueFlags & VK_QUEUE_EXTENDED_BIT) ? 'X' : '.'); 684 printf("\tqueueCount = %u\n", props->queueCount); 685 printf("\tmaxAtomicCounters = %u\n", props->maxAtomicCounters); 686 printf("\tsupportsTimestamps = %u\n", props->supportsTimestamps); 687} 688 689static void app_gpu_dump_memory_props(const struct app_gpu *gpu) 690{ 691 const VkPhysicalDeviceMemoryProperties *props = &gpu->memory_props; 692 693 printf("VkPhysicalDeviceMemoryProperties\n"); 694 printf("\tsupportsMigration = %u\n", props->supportsMigration); 695} 696 697static void app_gpu_dump(const struct app_gpu *gpu) 698{ 699 uint32_t i; 700 701 printf("GPU%u\n", gpu->id); 702 app_gpu_dump_props(gpu); 703 printf("\n"); 704 app_gpu_dump_extensions(gpu); 705 printf("\n"); 706 app_gpu_dump_perf(gpu); 707 printf("\n"); 708 for (i = 0; i < gpu->queue_count; i++) { 709 app_gpu_dump_queue_props(gpu, i); 710 printf("\n"); 711 } 712 app_gpu_dump_memory_props(gpu); 713 printf("\n"); 714 app_dev_dump(&gpu->dev); 715} 716 717int main(int argc, char **argv) 718{ 719 struct app_gpu gpus[MAX_GPUS]; 720 VkPhysicalDevice objs[MAX_GPUS]; 721 uint32_t gpu_count, i; 722 VkResult err; 723 struct app_instance inst; 724 725 app_create_instance(&inst); 726 app_gpu_dump_instance_extensions(&inst); 727 728 err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, NULL); 729 if (err) 730 ERR_EXIT(err); 731 if (gpu_count > MAX_GPUS) { 732 printf("Too many GPUS found \n"); 733 ERR_EXIT(VK_ERROR_UNKNOWN); 734 } 735 err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, objs); 736 if (err) 737 ERR_EXIT(err); 738 739 for (i = 0; i < gpu_count; i++) { 740 app_gpu_init(&gpus[i], i, objs[i]); 741 app_gpu_dump(&gpus[i]); 742 printf("\n\n"); 743 } 744 745 for (i = 0; i < gpu_count; i++) 746 app_gpu_destroy(&gpus[i]); 747 748 app_destroy_instance(&inst); 749 750 return 0; 751} 752 753#ifdef _WIN32 754 755// Create a console window with a large scrollback size to which to send stdout. 756// Returns true if console window was successfully created, false otherwise. 757bool SetStdOutToNewConsole() 758{ 759 // don't do anything if we already have a console 760 if (GetStdHandle(STD_OUTPUT_HANDLE)) 761 return false; 762 763 // allocate a console for this app 764 AllocConsole(); 765 766 // redirect unbuffered STDOUT to the console 767 HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); 768 int fileDescriptor = _open_osfhandle((intptr_t)consoleHandle, _O_TEXT); 769 FILE *fp = _fdopen( fileDescriptor, "w" ); 770 *stdout = *fp; 771 setvbuf( stdout, NULL, _IONBF, 0 ); 772 773 // make the console window bigger 774 CONSOLE_SCREEN_BUFFER_INFO csbi; 775 SMALL_RECT r; 776 COORD bufferSize; 777 if (!GetConsoleScreenBufferInfo(consoleHandle, &csbi)) 778 return false; 779 bufferSize.X = csbi.dwSize.X; 780 bufferSize.Y = 1000; 781 if (!SetConsoleScreenBufferSize(consoleHandle, bufferSize)) 782 return false; 783 r.Left = r.Top = 0; 784 r.Right = csbi.dwSize.X-1; 785 r.Bottom = 60; 786 if (!SetConsoleWindowInfo(consoleHandle, true, &r)) 787 return false; 788 789 // change the console window title 790 if (!SetConsoleTitle(TEXT(APP_SHORT_NAME))) 791 return false; 792 793 return true; 794} 795 796int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nCmdShow) 797{ 798 char *argv = pCmdLine; 799 consoleCreated = SetStdOutToNewConsole(); 800 main(1, &argv); 801 fflush(stdout); 802 if (consoleCreated) 803 Sleep(INFINITE); 804} 805#endif 806