vulkaninfo.c revision 8a0cc4ba66ff6142eb4794e1f766cee5a4bd0349
1/* 2 * Copyright (c) 2015-2016 The Khronos Group Inc. 3 * Copyright (c) 2015-2016 Valve Corporation 4 * Copyright (c) 2015-2016 LunarG, Inc. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> 19 * Author: David Pinedo <david@lunarg.com> 20 * Author: Mark Lobodzinski <mark@lunarg.com> 21 * Author: Rene Lindsay <rene@lunarg.com> 22 */ 23#include <assert.h> 24#include <inttypes.h> 25#include <stdbool.h> 26#include <stdio.h> 27#include <stdlib.h> 28#include <string.h> 29 30#ifdef _WIN32 31#include <fcntl.h> 32#include <io.h> 33#endif // _WIN32 34 35#ifdef __linux__ 36#include <X11/Xutil.h> 37#endif 38 39#include <vulkan/vulkan.h> 40 41#define ERR(err) \ 42 printf("%s:%d: failed with %s\n", __FILE__, __LINE__, \ 43 vk_result_string(err)); 44 45#ifdef _WIN32 46 47#define snprintf _snprintf 48 49// Returns nonzero if the console is used only for this process. Will return 50// zero if another process (such as cmd.exe) is also attached. 51static int ConsoleIsExclusive(void) { 52 DWORD pids[2]; 53 DWORD num_pids = GetConsoleProcessList(pids, ARRAYSIZE(pids)); 54 return num_pids <= 1; 55} 56 57#define WAIT_FOR_CONSOLE_DESTROY \ 58 do { \ 59 if (ConsoleIsExclusive()) \ 60 Sleep(INFINITE); \ 61 } while (0) 62#else 63#define WAIT_FOR_CONSOLE_DESTROY 64#endif 65 66#define ERR_EXIT(err) \ 67 do { \ 68 ERR(err); \ 69 fflush(stdout); \ 70 WAIT_FOR_CONSOLE_DESTROY; \ 71 exit(-1); \ 72 } while (0) 73 74#if defined(NDEBUG) && defined(__GNUC__) 75#define U_ASSERT_ONLY __attribute__((unused)) 76#else 77#define U_ASSERT_ONLY 78#endif 79 80#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 81 82#define MAX_GPUS 8 83 84#define MAX_QUEUE_TYPES 5 85#define APP_SHORT_NAME "vulkaninfo" 86 87struct app_gpu; 88 89struct app_dev { 90 struct app_gpu *gpu; /* point back to the GPU */ 91 92 VkDevice obj; 93 94 VkFormatProperties format_props[VK_FORMAT_RANGE_SIZE]; 95}; 96 97struct layer_extension_list { 98 VkLayerProperties layer_properties; 99 uint32_t extension_count; 100 VkExtensionProperties *extension_properties; 101}; 102 103struct app_instance { 104 VkInstance instance; 105 uint32_t global_layer_count; 106 struct layer_extension_list *global_layers; 107 uint32_t global_extension_count; 108 VkExtensionProperties *global_extensions; // Instance Extensions 109 110 PFN_vkGetPhysicalDeviceSurfaceSupportKHR 111 vkGetPhysicalDeviceSurfaceSupportKHR; 112 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR 113 vkGetPhysicalDeviceSurfaceCapabilitiesKHR; 114 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR 115 vkGetPhysicalDeviceSurfaceFormatsKHR; 116 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR 117 vkGetPhysicalDeviceSurfacePresentModesKHR; 118 119 VkSurfaceKHR surface; 120 int width, height; 121 122#ifdef VK_USE_PLATFORM_WIN32_KHR 123 HINSTANCE hInstance; // Windows Instance 124 HWND hWnd; // window handle 125#endif 126 127#ifdef VK_USE_PLATFORM_XCB_KHR 128 xcb_connection_t *xcb_connection; 129 xcb_screen_t *xcb_screen; 130 xcb_window_t xcb_window; 131#endif 132 133#ifdef VK_USE_PLATFORM_XLIB_KHR 134 Display *xlib_display; 135 Window xlib_window; 136#endif 137 138#ifdef VK_USE_PLATFORM_ANDROID_KHR // TODO 139 ANativeWindow *window; 140#endif 141}; 142 143struct app_gpu { 144 uint32_t id; 145 VkPhysicalDevice obj; 146 147 VkPhysicalDeviceProperties props; 148 149 uint32_t queue_count; 150 VkQueueFamilyProperties *queue_props; 151 VkDeviceQueueCreateInfo *queue_reqs; 152 153 VkPhysicalDeviceMemoryProperties memory_props; 154 VkPhysicalDeviceFeatures features; 155 VkPhysicalDevice limits; 156 157 uint32_t device_layer_count; 158 struct layer_extension_list *device_layers; 159 160 uint32_t device_extension_count; 161 VkExtensionProperties *device_extensions; 162 163 struct app_dev dev; 164}; 165 166static VKAPI_ATTR VkBool32 VKAPI_CALL 167dbg_callback(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, 168 uint64_t srcObject, size_t location, int32_t msgCode, 169 const char *pLayerPrefix, const char *pMsg, void *pUserData) { 170 char *message = (char *)malloc(strlen(pMsg) + 100); 171 172 assert(message); 173 174 if (msgFlags & VK_DEBUG_REPORT_ERROR_BIT_EXT) { 175 sprintf(message, "ERROR: [%s] Code %d : %s", pLayerPrefix, msgCode, 176 pMsg); 177 } else if (msgFlags & VK_DEBUG_REPORT_WARNING_BIT_EXT) { 178 sprintf(message, "WARNING: [%s] Code %d : %s", pLayerPrefix, msgCode, 179 pMsg); 180 } else if (msgFlags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) { 181 sprintf(message, "INFO: [%s] Code %d : %s", pLayerPrefix, msgCode, 182 pMsg); 183 } else if (msgFlags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) { 184 sprintf(message, "DEBUG: [%s] Code %d : %s", pLayerPrefix, msgCode, 185 pMsg); 186 } 187 188 printf("%s\n", message); 189 fflush(stdout); 190 free(message); 191 192 /* 193 * false indicates that layer should not bail-out of an 194 * API call that had validation failures. This may mean that the 195 * app dies inside the driver due to invalid parameter(s). 196 * That's what would happen without validation layers, so we'll 197 * keep that behavior here. 198 */ 199 return false; 200} 201 202static const char *vk_result_string(VkResult err) { 203 switch (err) { 204#define STR(r) \ 205 case r: \ 206 return #r 207 STR(VK_SUCCESS); 208 STR(VK_NOT_READY); 209 STR(VK_TIMEOUT); 210 STR(VK_EVENT_SET); 211 STR(VK_EVENT_RESET); 212 STR(VK_ERROR_INITIALIZATION_FAILED); 213 STR(VK_ERROR_OUT_OF_HOST_MEMORY); 214 STR(VK_ERROR_OUT_OF_DEVICE_MEMORY); 215 STR(VK_ERROR_DEVICE_LOST); 216 STR(VK_ERROR_LAYER_NOT_PRESENT); 217 STR(VK_ERROR_EXTENSION_NOT_PRESENT); 218 STR(VK_ERROR_MEMORY_MAP_FAILED); 219 STR(VK_ERROR_INCOMPATIBLE_DRIVER); 220#undef STR 221 default: 222 return "UNKNOWN_RESULT"; 223 } 224} 225 226static const char *vk_physical_device_type_string(VkPhysicalDeviceType type) { 227 switch (type) { 228#define STR(r) \ 229 case VK_PHYSICAL_DEVICE_TYPE_##r: \ 230 return #r 231 STR(OTHER); 232 STR(INTEGRATED_GPU); 233 STR(DISCRETE_GPU); 234 STR(VIRTUAL_GPU); 235#undef STR 236 default: 237 return "UNKNOWN_DEVICE"; 238 } 239} 240 241static const char *vk_format_string(VkFormat fmt) { 242 switch (fmt) { 243#define STR(r) \ 244 case VK_FORMAT_##r: \ 245 return #r 246 STR(UNDEFINED); 247 STR(R4G4_UNORM_PACK8); 248 STR(R4G4B4A4_UNORM_PACK16); 249 STR(B4G4R4A4_UNORM_PACK16); 250 STR(R5G6B5_UNORM_PACK16); 251 STR(B5G6R5_UNORM_PACK16); 252 STR(R5G5B5A1_UNORM_PACK16); 253 STR(B5G5R5A1_UNORM_PACK16); 254 STR(A1R5G5B5_UNORM_PACK16); 255 STR(R8_UNORM); 256 STR(R8_SNORM); 257 STR(R8_USCALED); 258 STR(R8_SSCALED); 259 STR(R8_UINT); 260 STR(R8_SINT); 261 STR(R8_SRGB); 262 STR(R8G8_UNORM); 263 STR(R8G8_SNORM); 264 STR(R8G8_USCALED); 265 STR(R8G8_SSCALED); 266 STR(R8G8_UINT); 267 STR(R8G8_SINT); 268 STR(R8G8_SRGB); 269 STR(R8G8B8_UNORM); 270 STR(R8G8B8_SNORM); 271 STR(R8G8B8_USCALED); 272 STR(R8G8B8_SSCALED); 273 STR(R8G8B8_UINT); 274 STR(R8G8B8_SINT); 275 STR(R8G8B8_SRGB); 276 STR(B8G8R8_UNORM); 277 STR(B8G8R8_SNORM); 278 STR(B8G8R8_USCALED); 279 STR(B8G8R8_SSCALED); 280 STR(B8G8R8_UINT); 281 STR(B8G8R8_SINT); 282 STR(B8G8R8_SRGB); 283 STR(R8G8B8A8_UNORM); 284 STR(R8G8B8A8_SNORM); 285 STR(R8G8B8A8_USCALED); 286 STR(R8G8B8A8_SSCALED); 287 STR(R8G8B8A8_UINT); 288 STR(R8G8B8A8_SINT); 289 STR(R8G8B8A8_SRGB); 290 STR(B8G8R8A8_UNORM); 291 STR(B8G8R8A8_SNORM); 292 STR(B8G8R8A8_USCALED); 293 STR(B8G8R8A8_SSCALED); 294 STR(B8G8R8A8_UINT); 295 STR(B8G8R8A8_SINT); 296 STR(B8G8R8A8_SRGB); 297 STR(A8B8G8R8_UNORM_PACK32); 298 STR(A8B8G8R8_SNORM_PACK32); 299 STR(A8B8G8R8_USCALED_PACK32); 300 STR(A8B8G8R8_SSCALED_PACK32); 301 STR(A8B8G8R8_UINT_PACK32); 302 STR(A8B8G8R8_SINT_PACK32); 303 STR(A8B8G8R8_SRGB_PACK32); 304 STR(A2R10G10B10_UNORM_PACK32); 305 STR(A2R10G10B10_SNORM_PACK32); 306 STR(A2R10G10B10_USCALED_PACK32); 307 STR(A2R10G10B10_SSCALED_PACK32); 308 STR(A2R10G10B10_UINT_PACK32); 309 STR(A2R10G10B10_SINT_PACK32); 310 STR(A2B10G10R10_UNORM_PACK32); 311 STR(A2B10G10R10_SNORM_PACK32); 312 STR(A2B10G10R10_USCALED_PACK32); 313 STR(A2B10G10R10_SSCALED_PACK32); 314 STR(A2B10G10R10_UINT_PACK32); 315 STR(A2B10G10R10_SINT_PACK32); 316 STR(R16_UNORM); 317 STR(R16_SNORM); 318 STR(R16_USCALED); 319 STR(R16_SSCALED); 320 STR(R16_UINT); 321 STR(R16_SINT); 322 STR(R16_SFLOAT); 323 STR(R16G16_UNORM); 324 STR(R16G16_SNORM); 325 STR(R16G16_USCALED); 326 STR(R16G16_SSCALED); 327 STR(R16G16_UINT); 328 STR(R16G16_SINT); 329 STR(R16G16_SFLOAT); 330 STR(R16G16B16_UNORM); 331 STR(R16G16B16_SNORM); 332 STR(R16G16B16_USCALED); 333 STR(R16G16B16_SSCALED); 334 STR(R16G16B16_UINT); 335 STR(R16G16B16_SINT); 336 STR(R16G16B16_SFLOAT); 337 STR(R16G16B16A16_UNORM); 338 STR(R16G16B16A16_SNORM); 339 STR(R16G16B16A16_USCALED); 340 STR(R16G16B16A16_SSCALED); 341 STR(R16G16B16A16_UINT); 342 STR(R16G16B16A16_SINT); 343 STR(R16G16B16A16_SFLOAT); 344 STR(R32_UINT); 345 STR(R32_SINT); 346 STR(R32_SFLOAT); 347 STR(R32G32_UINT); 348 STR(R32G32_SINT); 349 STR(R32G32_SFLOAT); 350 STR(R32G32B32_UINT); 351 STR(R32G32B32_SINT); 352 STR(R32G32B32_SFLOAT); 353 STR(R32G32B32A32_UINT); 354 STR(R32G32B32A32_SINT); 355 STR(R32G32B32A32_SFLOAT); 356 STR(R64_UINT); 357 STR(R64_SINT); 358 STR(R64_SFLOAT); 359 STR(R64G64_UINT); 360 STR(R64G64_SINT); 361 STR(R64G64_SFLOAT); 362 STR(R64G64B64_UINT); 363 STR(R64G64B64_SINT); 364 STR(R64G64B64_SFLOAT); 365 STR(R64G64B64A64_UINT); 366 STR(R64G64B64A64_SINT); 367 STR(R64G64B64A64_SFLOAT); 368 STR(B10G11R11_UFLOAT_PACK32); 369 STR(E5B9G9R9_UFLOAT_PACK32); 370 STR(D16_UNORM); 371 STR(X8_D24_UNORM_PACK32); 372 STR(D32_SFLOAT); 373 STR(S8_UINT); 374 STR(D16_UNORM_S8_UINT); 375 STR(D24_UNORM_S8_UINT); 376 STR(D32_SFLOAT_S8_UINT); 377 STR(BC1_RGB_UNORM_BLOCK); 378 STR(BC1_RGB_SRGB_BLOCK); 379 STR(BC2_UNORM_BLOCK); 380 STR(BC2_SRGB_BLOCK); 381 STR(BC3_UNORM_BLOCK); 382 STR(BC3_SRGB_BLOCK); 383 STR(BC4_UNORM_BLOCK); 384 STR(BC4_SNORM_BLOCK); 385 STR(BC5_UNORM_BLOCK); 386 STR(BC5_SNORM_BLOCK); 387 STR(BC6H_UFLOAT_BLOCK); 388 STR(BC6H_SFLOAT_BLOCK); 389 STR(BC7_UNORM_BLOCK); 390 STR(BC7_SRGB_BLOCK); 391 STR(ETC2_R8G8B8_UNORM_BLOCK); 392 STR(ETC2_R8G8B8A1_UNORM_BLOCK); 393 STR(ETC2_R8G8B8A8_UNORM_BLOCK); 394 STR(EAC_R11_UNORM_BLOCK); 395 STR(EAC_R11_SNORM_BLOCK); 396 STR(EAC_R11G11_UNORM_BLOCK); 397 STR(EAC_R11G11_SNORM_BLOCK); 398 STR(ASTC_4x4_UNORM_BLOCK); 399 STR(ASTC_4x4_SRGB_BLOCK); 400 STR(ASTC_5x4_UNORM_BLOCK); 401 STR(ASTC_5x4_SRGB_BLOCK); 402 STR(ASTC_5x5_UNORM_BLOCK); 403 STR(ASTC_5x5_SRGB_BLOCK); 404 STR(ASTC_6x5_UNORM_BLOCK); 405 STR(ASTC_6x5_SRGB_BLOCK); 406 STR(ASTC_6x6_UNORM_BLOCK); 407 STR(ASTC_6x6_SRGB_BLOCK); 408 STR(ASTC_8x5_UNORM_BLOCK); 409 STR(ASTC_8x5_SRGB_BLOCK); 410 STR(ASTC_8x6_UNORM_BLOCK); 411 STR(ASTC_8x6_SRGB_BLOCK); 412 STR(ASTC_8x8_UNORM_BLOCK); 413 STR(ASTC_8x8_SRGB_BLOCK); 414 STR(ASTC_10x5_UNORM_BLOCK); 415 STR(ASTC_10x5_SRGB_BLOCK); 416 STR(ASTC_10x6_UNORM_BLOCK); 417 STR(ASTC_10x6_SRGB_BLOCK); 418 STR(ASTC_10x8_UNORM_BLOCK); 419 STR(ASTC_10x8_SRGB_BLOCK); 420 STR(ASTC_10x10_UNORM_BLOCK); 421 STR(ASTC_10x10_SRGB_BLOCK); 422 STR(ASTC_12x10_UNORM_BLOCK); 423 STR(ASTC_12x10_SRGB_BLOCK); 424 STR(ASTC_12x12_UNORM_BLOCK); 425 STR(ASTC_12x12_SRGB_BLOCK); 426#undef STR 427 default: 428 return "UNKNOWN_FORMAT"; 429 } 430} 431 432static void app_dev_init_formats(struct app_dev *dev) { 433 VkFormat f; 434 435 for (f = 0; f < VK_FORMAT_RANGE_SIZE; f++) { 436 const VkFormat fmt = f; 437 438 vkGetPhysicalDeviceFormatProperties(dev->gpu->obj, fmt, 439 &dev->format_props[f]); 440 } 441} 442 443static void extract_version(uint32_t version, uint32_t *major, uint32_t *minor, 444 uint32_t *patch) { 445 *major = version >> 22; 446 *minor = (version >> 12) & 0x3ff; 447 *patch = version & 0xfff; 448} 449 450static void app_get_physical_device_layer_extensions( 451 struct app_gpu *gpu, char *layer_name, uint32_t *extension_count, 452 VkExtensionProperties **extension_properties) { 453 VkResult err; 454 uint32_t ext_count = 0; 455 VkExtensionProperties *ext_ptr = NULL; 456 457 /* repeat get until VK_INCOMPLETE goes away */ 458 do { 459 err = vkEnumerateDeviceExtensionProperties(gpu->obj, layer_name, 460 &ext_count, NULL); 461 assert(!err); 462 463 if (ext_ptr) { 464 free(ext_ptr); 465 } 466 ext_ptr = malloc(ext_count * sizeof(VkExtensionProperties)); 467 err = vkEnumerateDeviceExtensionProperties(gpu->obj, layer_name, 468 &ext_count, ext_ptr); 469 } while (err == VK_INCOMPLETE); 470 assert(!err); 471 472 *extension_count = ext_count; 473 *extension_properties = ext_ptr; 474} 475 476static void app_dev_init(struct app_dev *dev, struct app_gpu *gpu) { 477 VkDeviceCreateInfo info = { 478 .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, 479 .pNext = NULL, 480 .queueCreateInfoCount = 0, 481 .pQueueCreateInfos = NULL, 482 .enabledLayerCount = 0, 483 .ppEnabledLayerNames = NULL, 484 .enabledExtensionCount = 0, 485 .ppEnabledExtensionNames = NULL, 486 }; 487 VkResult U_ASSERT_ONLY err; 488 489 uint32_t count = 0; 490 491 // Scan layers 492 VkLayerProperties *device_layer_properties = NULL; 493 struct layer_extension_list *device_layers = NULL; 494 495 do { 496 err = vkEnumerateDeviceLayerProperties(gpu->obj, &count, NULL); 497 assert(!err); 498 499 if (device_layer_properties) { 500 free(device_layer_properties); 501 } 502 device_layer_properties = malloc(sizeof(VkLayerProperties) * count); 503 assert(device_layer_properties); 504 505 if (device_layers) { 506 free(device_layers); 507 } 508 device_layers = malloc(sizeof(struct layer_extension_list) * count); 509 assert(device_layers); 510 511 err = vkEnumerateDeviceLayerProperties(gpu->obj, &count, 512 device_layer_properties); 513 } while (err == VK_INCOMPLETE); 514 assert(!err); 515 516 gpu->device_layer_count = count; 517 gpu->device_layers = device_layers; 518 519 for (uint32_t i = 0; i < gpu->device_layer_count; i++) { 520 VkLayerProperties *src_info = &device_layer_properties[i]; 521 struct layer_extension_list *dst_info = &gpu->device_layers[i]; 522 memcpy(&dst_info->layer_properties, src_info, 523 sizeof(VkLayerProperties)); 524 525 // Save away layer extension info for report 526 app_get_physical_device_layer_extensions( 527 gpu, src_info->layerName, &dst_info->extension_count, 528 &dst_info->extension_properties); 529 } 530 free(device_layer_properties); 531 532 app_get_physical_device_layer_extensions( 533 gpu, NULL, &gpu->device_extension_count, &gpu->device_extensions); 534 535 fflush(stdout); 536 537 /* request all queues */ 538 info.queueCreateInfoCount = gpu->queue_count; 539 info.pQueueCreateInfos = gpu->queue_reqs; 540 541 info.enabledLayerCount = 0; 542 info.ppEnabledLayerNames = NULL; 543 info.enabledExtensionCount = 0; 544 info.ppEnabledExtensionNames = NULL; 545 dev->gpu = gpu; 546 err = vkCreateDevice(gpu->obj, &info, NULL, &dev->obj); 547 if (err) 548 ERR_EXIT(err); 549} 550 551static void app_dev_destroy(struct app_dev *dev) { 552 vkDestroyDevice(dev->obj, NULL); 553} 554 555static void 556app_get_global_layer_extensions(char *layer_name, uint32_t *extension_count, 557 VkExtensionProperties **extension_properties) { 558 VkResult err; 559 uint32_t ext_count = 0; 560 VkExtensionProperties *ext_ptr = NULL; 561 562 /* repeat get until VK_INCOMPLETE goes away */ 563 do { 564 // gets the extension count if the last parameter is NULL 565 err = vkEnumerateInstanceExtensionProperties(layer_name, &ext_count, 566 NULL); 567 assert(!err); 568 569 if (ext_ptr) { 570 free(ext_ptr); 571 } 572 ext_ptr = malloc(ext_count * sizeof(VkExtensionProperties)); 573 // gets the extension properties if the last parameter is not NULL 574 err = vkEnumerateInstanceExtensionProperties(layer_name, &ext_count, 575 ext_ptr); 576 } while (err == VK_INCOMPLETE); 577 assert(!err); 578 *extension_count = ext_count; 579 *extension_properties = ext_ptr; 580} 581 582/* Gets a list of layer and instance extensions */ 583static void app_get_instance_extensions(struct app_instance *inst) { 584 VkResult U_ASSERT_ONLY err; 585 586 uint32_t count = 0; 587 588 /* Scan layers */ 589 VkLayerProperties *global_layer_properties = NULL; 590 struct layer_extension_list *global_layers = NULL; 591 592 do { 593 err = vkEnumerateInstanceLayerProperties(&count, NULL); 594 assert(!err); 595 596 if (global_layer_properties) { 597 free(global_layer_properties); 598 } 599 global_layer_properties = malloc(sizeof(VkLayerProperties) * count); 600 assert(global_layer_properties); 601 602 if (global_layers) { 603 free(global_layers); 604 } 605 global_layers = malloc(sizeof(struct layer_extension_list) * count); 606 assert(global_layers); 607 608 err = 609 vkEnumerateInstanceLayerProperties(&count, global_layer_properties); 610 } while (err == VK_INCOMPLETE); 611 assert(!err); 612 613 inst->global_layer_count = count; 614 inst->global_layers = global_layers; 615 616 for (uint32_t i = 0; i < inst->global_layer_count; i++) { 617 VkLayerProperties *src_info = &global_layer_properties[i]; 618 struct layer_extension_list *dst_info = &inst->global_layers[i]; 619 memcpy(&dst_info->layer_properties, src_info, 620 sizeof(VkLayerProperties)); 621 622 /* Save away layer extension info for report */ 623 /* Gets layer extensions, if first parameter is not NULL*/ 624 app_get_global_layer_extensions(src_info->layerName, 625 &dst_info->extension_count, 626 &dst_info->extension_properties); 627 } 628 free(global_layer_properties); 629 630 /* Collect global extensions */ 631 inst->global_extension_count = 0; 632 /* Gets instance extensions, if no layer was specified in teh first 633 * paramteter */ 634 app_get_global_layer_extensions(NULL, &inst->global_extension_count, 635 &inst->global_extensions); 636} 637 638static void app_create_instance(struct app_instance *inst) { 639 app_get_instance_extensions(inst); 640 641//---Build a list of extensions to load--- 642#define MAX_EXTENSIONS 4 643 uint32_t i = 0; 644 uint32_t ext_count = 0; 645 const char *ext_names[MAX_EXTENSIONS]; // array of string pointers to 646 // extension names 647 for (i = 0; (i < inst->global_extension_count); i++) { 648 const char *found_name = inst->global_extensions[i].extensionName; 649 if (!strcmp(VK_KHR_SURFACE_EXTENSION_NAME, found_name)) 650 {ext_names[ext_count++] = VK_KHR_SURFACE_EXTENSION_NAME;} 651 } 652 653 if (ext_count) 654 for (i = 0; ((i < inst->global_extension_count) && 655 (ext_count < MAX_EXTENSIONS)); 656 i++) { 657 const char *found_name = inst->global_extensions[i].extensionName; 658#ifdef VK_USE_PLATFORM_WIN32_KHR 659 if (!strcmp(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, found_name)) 660 {ext_names[ext_count++] = VK_KHR_WIN32_SURFACE_EXTENSION_NAME;} 661#endif 662#ifdef VK_USE_PLATFORM_XCB_KHR 663 if (!strcmp(VK_KHR_XCB_SURFACE_EXTENSION_NAME, found_name)) 664 {ext_names[ext_count++] = VK_KHR_XCB_SURFACE_EXTENSION_NAME;} 665#endif 666#ifdef VK_USE_PLATFORM_XLIB_KHR 667 if (!strcmp(VK_KHR_XLIB_SURFACE_EXTENSION_NAME, found_name)) 668 {ext_names[ext_count++] = VK_KHR_XLIB_SURFACE_EXTENSION_NAME;} 669#endif 670#ifdef VK_USE_PLATFORM_ANDROID_KHR 671 if (!strcmp(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, found_name)) 672 {ext_names[ext_count++] = VK_KHR_ANDROID_SURFACE_EXTENSION_NAME;} 673#endif 674 } 675 // If we don't find the KHR_SURFACE extension and at least one other 676 // device-specific extension, 677 // then give up on reporting presentable surface formats." 678 if (ext_count < 2) 679 ext_count = 0; 680 //---------------------------------------- 681 682 const VkApplicationInfo app_info = { 683 .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, 684 .pNext = NULL, 685 .pApplicationName = APP_SHORT_NAME, 686 .applicationVersion = 1, 687 .pEngineName = APP_SHORT_NAME, 688 .engineVersion = 1, 689 .apiVersion = VK_API_VERSION_1_0, 690 }; 691 692 VkInstanceCreateInfo inst_info = { 693 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, 694 .pNext = NULL, 695 .pApplicationInfo = &app_info, 696 .enabledLayerCount = 0, 697 .ppEnabledLayerNames = NULL, 698 .enabledExtensionCount = ext_count, 699 .ppEnabledExtensionNames = ext_names, 700 }; 701 702 VkDebugReportCallbackCreateInfoEXT dbg_info; 703 memset(&dbg_info, 0, sizeof(dbg_info)); 704 dbg_info.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; 705 dbg_info.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | 706 VK_DEBUG_REPORT_WARNING_BIT_EXT | 707 VK_DEBUG_REPORT_INFORMATION_BIT_EXT; 708 dbg_info.pfnCallback = dbg_callback; 709 inst_info.pNext = &dbg_info; 710 711 VkResult U_ASSERT_ONLY err; 712 err = vkCreateInstance(&inst_info, NULL, &inst->instance); 713 if (err == VK_ERROR_INCOMPATIBLE_DRIVER) { 714 printf("Cannot create Vulkan instance.\n"); 715 ERR_EXIT(err); 716 } else if (err) { 717 ERR_EXIT(err); 718 } 719 720 if (ext_count > 0) { 721//--Load Extensions-- 722#define GET_INSTANCE_PROC_ADDR(ENTRYPOINT) \ 723 { \ 724 inst->ENTRYPOINT = \ 725 (void *)vkGetInstanceProcAddr(inst->instance, #ENTRYPOINT); \ 726 } 727 GET_INSTANCE_PROC_ADDR(vkGetPhysicalDeviceSurfaceSupportKHR) 728 GET_INSTANCE_PROC_ADDR(vkGetPhysicalDeviceSurfaceCapabilitiesKHR) 729 GET_INSTANCE_PROC_ADDR(vkGetPhysicalDeviceSurfaceFormatsKHR) 730 GET_INSTANCE_PROC_ADDR(vkGetPhysicalDeviceSurfacePresentModesKHR) 731#undef GET_INSTANCE_PROC_ADDR 732 } 733} 734 735//----------------------------------------------------------- 736 737static void app_destroy_instance(struct app_instance *inst) { 738 free(inst->global_extensions); 739 vkDestroyInstance(inst->instance, NULL); 740} 741 742static void app_gpu_init(struct app_gpu *gpu, uint32_t id, 743 VkPhysicalDevice obj) { 744 uint32_t i; 745 746 memset(gpu, 0, sizeof(*gpu)); 747 748 gpu->id = id; 749 gpu->obj = obj; 750 751 vkGetPhysicalDeviceProperties(gpu->obj, &gpu->props); 752 753 /* get queue count */ 754 vkGetPhysicalDeviceQueueFamilyProperties(gpu->obj, &gpu->queue_count, NULL); 755 756 gpu->queue_props = malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count); 757 758 if (!gpu->queue_props) 759 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); 760 vkGetPhysicalDeviceQueueFamilyProperties(gpu->obj, &gpu->queue_count, 761 gpu->queue_props); 762 763 /* set up queue requests */ 764 gpu->queue_reqs = malloc(sizeof(*gpu->queue_reqs) * gpu->queue_count); 765 if (!gpu->queue_reqs) 766 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); 767 for (i = 0; i < gpu->queue_count; i++) { 768 float *queue_priorities = 769 malloc(gpu->queue_props[i].queueCount * sizeof(float)); 770 memset(queue_priorities, 0, 771 gpu->queue_props[i].queueCount * sizeof(float)); 772 gpu->queue_reqs[i].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; 773 gpu->queue_reqs[i].pNext = NULL; 774 gpu->queue_reqs[i].queueFamilyIndex = i; 775 gpu->queue_reqs[i].queueCount = gpu->queue_props[i].queueCount; 776 gpu->queue_reqs[i].pQueuePriorities = queue_priorities; 777 } 778 779 vkGetPhysicalDeviceMemoryProperties(gpu->obj, &gpu->memory_props); 780 781 vkGetPhysicalDeviceFeatures(gpu->obj, &gpu->features); 782 783 app_dev_init(&gpu->dev, gpu); 784 app_dev_init_formats(&gpu->dev); 785} 786 787static void app_gpu_destroy(struct app_gpu *gpu) { 788 app_dev_destroy(&gpu->dev); 789 free(gpu->device_extensions); 790 791 for (uint32_t i = 0; i < gpu->queue_count; i++) { 792 free((void *)gpu->queue_reqs[i].pQueuePriorities); 793 } 794 free(gpu->queue_reqs); 795 free(gpu->queue_props); 796} 797 798// clang-format off 799 800//----------------------------------------------------------- 801 802//---------------------------Win32--------------------------- 803#ifdef VK_USE_PLATFORM_WIN32_KHR 804 805// MS-Windows event handling function: 806LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 807 return (DefWindowProc(hWnd, uMsg, wParam, lParam)); 808} 809 810static void app_create_win32_window(struct app_instance *inst) { 811 inst->hInstance = GetModuleHandle(NULL); 812 813 WNDCLASSEX win_class; 814 815 // Initialize the window class structure: 816 win_class.cbSize = sizeof(WNDCLASSEX); 817 win_class.style = CS_HREDRAW | CS_VREDRAW; 818 win_class.lpfnWndProc = WndProc; 819 win_class.cbClsExtra = 0; 820 win_class.cbWndExtra = 0; 821 win_class.hInstance = inst->hInstance; 822 win_class.hIcon = LoadIcon(NULL, IDI_APPLICATION); 823 win_class.hCursor = LoadCursor(NULL, IDC_ARROW); 824 win_class.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 825 win_class.lpszMenuName = NULL; 826 win_class.lpszClassName = APP_SHORT_NAME; 827 win_class.hInstance = inst->hInstance; 828 win_class.hIconSm = LoadIcon(NULL, IDI_WINLOGO); 829 // Register window class: 830 if (!RegisterClassEx(&win_class)) { 831 // It didn't work, so try to give a useful error: 832 printf("Failed to register the window class!\n"); 833 fflush(stdout); 834 exit(1); 835 } 836 // Create window with the registered class: 837 RECT wr = { 0, 0, inst->width, inst->height }; 838 AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); 839 inst->hWnd = CreateWindowEx(0, 840 APP_SHORT_NAME, // class name 841 APP_SHORT_NAME, // app name 842 //WS_VISIBLE | WS_SYSMENU | 843 WS_OVERLAPPEDWINDOW, // window style 844 100, 100, // x/y coords 845 wr.right - wr.left, // width 846 wr.bottom - wr.top, // height 847 NULL, // handle to parent 848 NULL, // handle to menu 849 inst->hInstance, // hInstance 850 NULL); // no extra parameters 851 if (!inst->hWnd) { 852 // It didn't work, so try to give a useful error: 853 printf("Failed to create a window!\n"); 854 fflush(stdout); 855 exit(1); 856 } 857} 858 859static void app_create_win32_surface(struct app_instance *inst, struct app_gpu *gpu) { 860 VkResult U_ASSERT_ONLY err; 861 VkWin32SurfaceCreateInfoKHR createInfo; 862 createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; 863 createInfo.pNext = NULL; 864 createInfo.flags = 0; 865 createInfo.hinstance = inst->hInstance; 866 createInfo.hwnd = inst->hWnd; 867 err = vkCreateWin32SurfaceKHR(inst->instance, &createInfo, NULL, &inst->surface); 868 assert(!err); 869} 870 871static void app_destroy_win32_window(struct app_instance *inst) { 872 DestroyWindow(inst->hWnd); 873} 874#endif //VK_USE_PLATFORM_WIN32_KHR 875//----------------------------------------------------------- 876 877static void app_destroy_surface(struct app_instance *inst) { //same for all platforms 878 vkDestroySurfaceKHR(inst->instance, inst->surface, NULL); 879} 880 881//----------------------------XCB---------------------------- 882 883#ifdef VK_USE_PLATFORM_XCB_KHR 884static void app_create_xcb_window(struct app_instance *inst) { 885 //--Init Connection-- 886 const xcb_setup_t *setup; 887 xcb_screen_iterator_t iter; 888 int scr; 889 890 inst->xcb_connection = xcb_connect(NULL, &scr); 891 if (inst->xcb_connection == NULL) { 892 printf("XCB failed to connect to the X server.\nExiting ...\n"); 893 fflush(stdout); 894 exit(1); 895 } 896 897 setup = xcb_get_setup(inst->xcb_connection); 898 iter = xcb_setup_roots_iterator(setup); 899 while (scr-- > 0) 900 xcb_screen_next(&iter); 901 902 inst->xcb_screen = iter.data; 903 //------------------- 904 905 inst->xcb_window = xcb_generate_id(inst->xcb_connection); 906 xcb_create_window(inst->xcb_connection, XCB_COPY_FROM_PARENT, inst->xcb_window, 907 inst->xcb_screen->root, 0, 0, inst->width, inst->height, 0, 908 XCB_WINDOW_CLASS_INPUT_OUTPUT, inst->xcb_screen->root_visual, 909 0, NULL); 910 911 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(inst->xcb_connection, 1, 12, "WM_PROTOCOLS"); 912 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(inst->xcb_connection, cookie, 0); 913 free(reply); 914} 915 916static void app_create_xcb_surface(struct app_instance *inst, struct app_gpu *gpu) { 917 VkResult U_ASSERT_ONLY err; 918 VkXcbSurfaceCreateInfoKHR xcb_createInfo; 919 xcb_createInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; 920 xcb_createInfo.pNext = NULL; 921 xcb_createInfo.flags = 0; 922 xcb_createInfo.connection = inst->xcb_connection; 923 xcb_createInfo.window = inst->xcb_window; 924 err = vkCreateXcbSurfaceKHR(inst->instance, &xcb_createInfo, NULL, &inst->surface); 925 assert(!err); 926} 927 928static void app_destroy_xcb_window(struct app_instance *inst) { 929 xcb_destroy_window(inst->xcb_connection, inst->xcb_window); 930 xcb_disconnect(inst->xcb_connection); 931} 932#endif //VK_USE_PLATFORM_XCB_KHR 933//----------------------------------------------------------- 934 935//----------------------------XLib--------------------------- 936#ifdef VK_USE_PLATFORM_XLIB_KHR 937static void app_create_xlib_window(struct app_instance *inst) { 938 inst->xlib_display = XOpenDisplay(NULL); 939 long visualMask = VisualScreenMask; 940 int numberOfVisuals; 941 942 XVisualInfo vInfoTemplate={}; 943 vInfoTemplate.screen = DefaultScreen(inst->xlib_display); 944 XVisualInfo *visualInfo = XGetVisualInfo(inst->xlib_display, visualMask, 945 &vInfoTemplate, &numberOfVisuals); 946 inst->xlib_window = XCreateWindow( 947 inst->xlib_display, RootWindow(inst->xlib_display, vInfoTemplate.screen), 0, 0, 948 inst->width, inst->height, 0, visualInfo->depth, InputOutput, 949 visualInfo->visual, 0, NULL); 950 951 XFlush(inst->xlib_display); 952} 953 954static void app_create_xlib_surface(struct app_instance *inst, struct app_gpu *gpu) { 955 VkResult U_ASSERT_ONLY err; 956 VkXlibSurfaceCreateInfoKHR createInfo; 957 createInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; 958 createInfo.pNext = NULL; 959 createInfo.flags = 0; 960 createInfo.dpy = inst->xlib_display; 961 createInfo.window = inst->xlib_window; 962 err = vkCreateXlibSurfaceKHR(inst->instance, &createInfo, NULL, &inst->surface); 963 assert(!err); 964} 965 966static void app_destroy_xlib_window(struct app_instance *inst) { 967 XDestroyWindow(inst->xlib_display, inst->xlib_window); 968 XCloseDisplay(inst->xlib_display); 969} 970#endif //VK_USE_PLATFORM_XLIB_KHR 971//----------------------------------------------------------- 972 973static int app_dump_surface_formats(struct app_instance *inst, struct app_gpu *gpu){ 974 // Get the list of VkFormat's that are supported: 975 VkResult U_ASSERT_ONLY err; 976 uint32_t formatCount=0; 977 err = inst->vkGetPhysicalDeviceSurfaceFormatsKHR(gpu->obj, inst->surface, &formatCount, NULL); 978 assert(!err); 979 VkSurfaceFormatKHR *surfFormats = (VkSurfaceFormatKHR *)malloc(formatCount * sizeof(VkSurfaceFormatKHR)); 980 err = inst->vkGetPhysicalDeviceSurfaceFormatsKHR(gpu->obj, inst->surface, &formatCount, surfFormats); 981 assert(!err); 982 printf("Format count = %d\n",formatCount); 983 uint32_t i; 984 for(i=0;i<formatCount;i++) printf("\t%s\n",vk_format_string(surfFormats[i].format)); 985 printf("\n"); 986 fflush(stdout); 987 return formatCount; 988} 989 990static void app_dev_dump_format_props(const struct app_dev *dev, VkFormat fmt) 991{ 992 const VkFormatProperties *props = &dev->format_props[fmt]; 993 struct { 994 const char *name; 995 VkFlags flags; 996 } features[3]; 997 uint32_t i; 998 999 features[0].name = "linearTiling FormatFeatureFlags"; 1000 features[0].flags = props->linearTilingFeatures; 1001 features[1].name = "optimalTiling FormatFeatureFlags"; 1002 features[1].flags = props->optimalTilingFeatures; 1003 features[2].name = "bufferFeatures FormatFeatureFlags"; 1004 features[2].flags = props->bufferFeatures; 1005 1006 printf("\nFORMAT_%s:", vk_format_string(fmt)); 1007 for (i = 0; i < ARRAY_SIZE(features); i++) { 1008 printf("\n\t%s:", features[i].name); 1009 if (features[i].flags == 0) { 1010 printf("\n\t\tNone"); 1011 } else { 1012 printf("%s%s%s%s%s%s%s%s%s%s%s%s%s%s", 1013 ((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) ? "\n\t\tVK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT" : ""), //0x0001 1014 ((features[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_IMAGE_BIT" : ""), //0x0002 1015 ((features[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT" : ""), //0x0004 1016 ((features[i].flags & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT) ? "\n\t\tVK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT" : ""), //0x0008 1017 ((features[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT" : ""), //0x0010 1018 ((features[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT" : ""), //0x0020 1019 ((features[i].flags & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) ? "\n\t\tVK_FORMAT_FEATURE_VERTEX_BUFFER_BIT" : ""), //0x0040 1020 ((features[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) ? "\n\t\tVK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT" : ""), //0x0080 1021 ((features[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT) ? "\n\t\tVK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT" : ""), //0x0100 1022 ((features[i].flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) ? "\n\t\tVK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT" : ""), //0x0200 1023 ((features[i].flags & VK_FORMAT_FEATURE_BLIT_SRC_BIT) ? "\n\t\tVK_FORMAT_FEATURE_BLIT_SRC_BIT" : ""), //0x0400 1024 ((features[i].flags & VK_FORMAT_FEATURE_BLIT_DST_BIT) ? "\n\t\tVK_FORMAT_FEATURE_BLIT_DST_BIT" : ""), //0x0800 1025 ((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT) ? "\n\t\tVK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT" : ""), //0x1000 1026 ((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG) ? "\n\t\tVK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG" : "")); //0x2000 1027 } 1028 } 1029 printf("\n"); 1030} 1031 1032 1033static void 1034app_dev_dump(const struct app_dev *dev) 1035{ 1036 VkFormat fmt; 1037 1038 for (fmt = 0; fmt < VK_FORMAT_RANGE_SIZE; fmt++) { 1039 app_dev_dump_format_props(dev, fmt); 1040 } 1041} 1042 1043#ifdef _WIN32 1044#define PRINTF_SIZE_T_SPECIFIER "%Iu" 1045#else 1046#define PRINTF_SIZE_T_SPECIFIER "%zu" 1047#endif 1048 1049static void app_gpu_dump_features(const struct app_gpu *gpu) 1050{ 1051 const VkPhysicalDeviceFeatures *features = &gpu->features; 1052 1053 printf("VkPhysicalDeviceFeatures:\n"); 1054 printf("=========================\n"); 1055 1056 printf("\trobustBufferAccess = %u\n", features->robustBufferAccess ); 1057 printf("\tfullDrawIndexUint32 = %u\n", features->fullDrawIndexUint32 ); 1058 printf("\timageCubeArray = %u\n", features->imageCubeArray ); 1059 printf("\tindependentBlend = %u\n", features->independentBlend ); 1060 printf("\tgeometryShader = %u\n", features->geometryShader ); 1061 printf("\ttessellationShader = %u\n", features->tessellationShader ); 1062 printf("\tsampleRateShading = %u\n", features->sampleRateShading ); 1063 printf("\tdualSrcBlend = %u\n", features->dualSrcBlend ); 1064 printf("\tlogicOp = %u\n", features->logicOp ); 1065 printf("\tmultiDrawIndirect = %u\n", features->multiDrawIndirect ); 1066 printf("\tdrawIndirectFirstInstance = %u\n", features->drawIndirectFirstInstance ); 1067 printf("\tdepthClamp = %u\n", features->depthClamp ); 1068 printf("\tdepthBiasClamp = %u\n", features->depthBiasClamp ); 1069 printf("\tfillModeNonSolid = %u\n", features->fillModeNonSolid ); 1070 printf("\tdepthBounds = %u\n", features->depthBounds ); 1071 printf("\twideLines = %u\n", features->wideLines ); 1072 printf("\tlargePoints = %u\n", features->largePoints ); 1073 printf("\ttextureCompressionETC2 = %u\n", features->textureCompressionETC2 ); 1074 printf("\ttextureCompressionASTC_LDR = %u\n", features->textureCompressionASTC_LDR ); 1075 printf("\ttextureCompressionBC = %u\n", features->textureCompressionBC ); 1076 printf("\tocclusionQueryPrecise = %u\n", features->occlusionQueryPrecise ); 1077 printf("\tpipelineStatisticsQuery = %u\n", features->pipelineStatisticsQuery ); 1078 printf("\tvertexSideEffects = %u\n", features->vertexPipelineStoresAndAtomics ); 1079 printf("\ttessellationSideEffects = %u\n", features->fragmentStoresAndAtomics ); 1080 printf("\tgeometrySideEffects = %u\n", features->shaderTessellationAndGeometryPointSize ); 1081 printf("\tshaderImageGatherExtended = %u\n", features->shaderImageGatherExtended ); 1082 printf("\tshaderStorageImageExtendedFormats = %u\n", features->shaderStorageImageExtendedFormats ); 1083 printf("\tshaderStorageImageMultisample = %u\n", features->shaderStorageImageMultisample ); 1084 printf("\tshaderStorageImageReadWithoutFormat = %u\n", features->shaderStorageImageReadWithoutFormat ); 1085 printf("\tshaderStorageImageWriteWithoutFormat = %u\n", features->shaderStorageImageWriteWithoutFormat ); 1086 printf("\tshaderUniformBufferArrayDynamicIndexing = %u\n", features->shaderUniformBufferArrayDynamicIndexing); 1087 printf("\tshaderSampledImageArrayDynamicIndexing = %u\n", features->shaderSampledImageArrayDynamicIndexing ); 1088 printf("\tshaderStorageBufferArrayDynamicIndexing = %u\n", features->shaderStorageBufferArrayDynamicIndexing); 1089 printf("\tshaderStorageImageArrayDynamicIndexing = %u\n", features->shaderStorageImageArrayDynamicIndexing ); 1090 printf("\tshaderClipDistance = %u\n", features->shaderClipDistance ); 1091 printf("\tshaderCullDistance = %u\n", features->shaderCullDistance ); 1092 printf("\tshaderFloat64 = %u\n", features->shaderFloat64 ); 1093 printf("\tshaderInt64 = %u\n", features->shaderInt64 ); 1094 printf("\tshaderInt16 = %u\n", features->shaderInt16 ); 1095 printf("\tshaderResourceResidency = %u\n", features->shaderResourceResidency ); 1096 printf("\tshaderResourceMinLod = %u\n", features->shaderResourceMinLod ); 1097 printf("\talphaToOne = %u\n", features->alphaToOne ); 1098 printf("\tsparseBinding = %u\n", features->sparseBinding ); 1099 printf("\tsparseResidencyBuffer = %u\n", features->sparseResidencyBuffer ); 1100 printf("\tsparseResidencyImage2D = %u\n", features->sparseResidencyImage2D ); 1101 printf("\tsparseResidencyImage3D = %u\n", features->sparseResidencyImage3D ); 1102 printf("\tsparseResidency2Samples = %u\n", features->sparseResidency2Samples ); 1103 printf("\tsparseResidency4Samples = %u\n", features->sparseResidency4Samples ); 1104 printf("\tsparseResidency8Samples = %u\n", features->sparseResidency8Samples ); 1105 printf("\tsparseResidency16Samples = %u\n", features->sparseResidency16Samples ); 1106 printf("\tsparseResidencyAliased = %u\n", features->sparseResidencyAliased ); 1107 printf("\tvariableMultisampleRate = %u\n", features->variableMultisampleRate ); 1108 printf("\tiheritedQueries = %u\n", features->inheritedQueries ); 1109} 1110 1111static void app_dump_sparse_props(const VkPhysicalDeviceSparseProperties *sparseProps) 1112{ 1113 1114 printf("\tVkPhysicalDeviceSparseProperties:\n"); 1115 printf("\t---------------------------------\n"); 1116 1117 printf("\t\tresidencyStandard2DBlockShape = %u\n", sparseProps->residencyStandard2DBlockShape ); 1118 printf("\t\tresidencyStandard2DMultisampleBlockShape = %u\n", sparseProps->residencyStandard2DMultisampleBlockShape); 1119 printf("\t\tresidencyStandard3DBlockShape = %u\n", sparseProps->residencyStandard3DBlockShape ); 1120 printf("\t\tresidencyAlignedMipSize = %u\n", sparseProps->residencyAlignedMipSize ); 1121 printf("\t\tresidencyNonResidentStrict = %u\n", sparseProps->residencyNonResidentStrict ); 1122} 1123 1124static void app_dump_limits(const VkPhysicalDeviceLimits *limits) 1125{ 1126 printf("\tVkPhysicalDeviceLimits:\n"); 1127 printf("\t-----------------------\n"); 1128 printf("\t\tmaxImageDimension1D = %u\n", limits->maxImageDimension1D ); 1129 printf("\t\tmaxImageDimension2D = %u\n", limits->maxImageDimension2D ); 1130 printf("\t\tmaxImageDimension3D = %u\n", limits->maxImageDimension3D ); 1131 printf("\t\tmaxImageDimensionCube = %u\n", limits->maxImageDimensionCube ); 1132 printf("\t\tmaxImageArrayLayers = %u\n", limits->maxImageArrayLayers ); 1133 printf("\t\tmaxTexelBufferElements = 0x%" PRIxLEAST32 "\n", limits->maxTexelBufferElements ); 1134 printf("\t\tmaxUniformBufferRange = 0x%" PRIxLEAST32 "\n", limits->maxUniformBufferRange ); 1135 printf("\t\tmaxStorageBufferRange = 0x%" PRIxLEAST32 "\n", limits->maxStorageBufferRange ); 1136 printf("\t\tmaxPushConstantsSize = %u\n", limits->maxPushConstantsSize ); 1137 printf("\t\tmaxMemoryAllocationCount = %u\n", limits->maxMemoryAllocationCount ); 1138 printf("\t\tmaxSamplerAllocationCount = %u\n", limits->maxSamplerAllocationCount ); 1139 printf("\t\tbufferImageGranularity = 0x%" PRIxLEAST64 "\n", limits->bufferImageGranularity ); 1140 printf("\t\tsparseAddressSpaceSize = 0x%" PRIxLEAST64 "\n", limits->sparseAddressSpaceSize ); 1141 printf("\t\tmaxBoundDescriptorSets = %u\n", limits->maxBoundDescriptorSets ); 1142 printf("\t\tmaxPerStageDescriptorSamplers = %u\n", limits->maxPerStageDescriptorSamplers ); 1143 printf("\t\tmaxPerStageDescriptorUniformBuffers = %u\n", limits->maxPerStageDescriptorUniformBuffers ); 1144 printf("\t\tmaxPerStageDescriptorStorageBuffers = %u\n", limits->maxPerStageDescriptorStorageBuffers ); 1145 printf("\t\tmaxPerStageDescriptorSampledImages = %u\n", limits->maxPerStageDescriptorSampledImages ); 1146 printf("\t\tmaxPerStageDescriptorStorageImages = %u\n", limits->maxPerStageDescriptorStorageImages ); 1147 printf("\t\tmaxPerStageDescriptorInputAttachments = %u\n", limits->maxPerStageDescriptorInputAttachments ); 1148 printf("\t\tmaxPerStageResources = %u\n", limits->maxPerStageResources ); 1149 printf("\t\tmaxDescriptorSetSamplers = %u\n", limits->maxDescriptorSetSamplers ); 1150 printf("\t\tmaxDescriptorSetUniformBuffers = %u\n", limits->maxDescriptorSetUniformBuffers ); 1151 printf("\t\tmaxDescriptorSetUniformBuffersDynamic = %u\n", limits->maxDescriptorSetUniformBuffersDynamic ); 1152 printf("\t\tmaxDescriptorSetStorageBuffers = %u\n", limits->maxDescriptorSetStorageBuffers ); 1153 printf("\t\tmaxDescriptorSetStorageBuffersDynamic = %u\n", limits->maxDescriptorSetStorageBuffersDynamic ); 1154 printf("\t\tmaxDescriptorSetSampledImages = %u\n", limits->maxDescriptorSetSampledImages ); 1155 printf("\t\tmaxDescriptorSetStorageImages = %u\n", limits->maxDescriptorSetStorageImages ); 1156 printf("\t\tmaxDescriptorSetInputAttachments = %u\n", limits->maxDescriptorSetInputAttachments ); 1157 printf("\t\tmaxVertexInputAttributes = %u\n", limits->maxVertexInputAttributes ); 1158 printf("\t\tmaxVertexInputBindings = %u\n", limits->maxVertexInputBindings ); 1159 printf("\t\tmaxVertexInputAttributeOffset = 0x%" PRIxLEAST32 "\n", limits->maxVertexInputAttributeOffset ); 1160 printf("\t\tmaxVertexInputBindingStride = 0x%" PRIxLEAST32 "\n", limits->maxVertexInputBindingStride ); 1161 printf("\t\tmaxVertexOutputComponents = %u\n", limits->maxVertexOutputComponents ); 1162 printf("\t\tmaxTessellationGenerationLevel = %u\n", limits->maxTessellationGenerationLevel ); 1163 printf("\t\tmaxTessellationPatchSize = %u\n", limits->maxTessellationPatchSize ); 1164 printf("\t\tmaxTessellationControlPerVertexInputComponents = %u\n", limits->maxTessellationControlPerVertexInputComponents ); 1165 printf("\t\tmaxTessellationControlPerVertexOutputComponents = %u\n", limits->maxTessellationControlPerVertexOutputComponents); 1166 printf("\t\tmaxTessellationControlPerPatchOutputComponents = %u\n", limits->maxTessellationControlPerPatchOutputComponents ); 1167 printf("\t\tmaxTessellationControlTotalOutputComponents = %u\n", limits->maxTessellationControlTotalOutputComponents ); 1168 printf("\t\tmaxTessellationEvaluationInputComponents = %u\n", limits->maxTessellationEvaluationInputComponents ); 1169 printf("\t\tmaxTessellationEvaluationOutputComponents = %u\n", limits->maxTessellationEvaluationOutputComponents ); 1170 printf("\t\tmaxGeometryShaderInvocations = %u\n", limits->maxGeometryShaderInvocations ); 1171 printf("\t\tmaxGeometryInputComponents = %u\n", limits->maxGeometryInputComponents ); 1172 printf("\t\tmaxGeometryOutputComponents = %u\n", limits->maxGeometryOutputComponents ); 1173 printf("\t\tmaxGeometryOutputVertices = %u\n", limits->maxGeometryOutputVertices ); 1174 printf("\t\tmaxGeometryTotalOutputComponents = %u\n", limits->maxGeometryTotalOutputComponents ); 1175 printf("\t\tmaxFragmentInputComponents = %u\n", limits->maxFragmentInputComponents ); 1176 printf("\t\tmaxFragmentOutputAttachments = %u\n", limits->maxFragmentOutputAttachments ); 1177 printf("\t\tmaxFragmentDualSrcAttachments = %u\n", limits->maxFragmentDualSrcAttachments ); 1178 printf("\t\tmaxFragmentCombinedOutputResources = %u\n", limits->maxFragmentCombinedOutputResources ); 1179 printf("\t\tmaxComputeSharedMemorySize = 0x%" PRIxLEAST32 "\n", limits->maxComputeSharedMemorySize ); 1180 printf("\t\tmaxComputeWorkGroupCount[0] = %u\n", limits->maxComputeWorkGroupCount[0] ); 1181 printf("\t\tmaxComputeWorkGroupCount[1] = %u\n", limits->maxComputeWorkGroupCount[1] ); 1182 printf("\t\tmaxComputeWorkGroupCount[2] = %u\n", limits->maxComputeWorkGroupCount[2] ); 1183 printf("\t\tmaxComputeWorkGroupInvocations = %u\n", limits->maxComputeWorkGroupInvocations ); 1184 printf("\t\tmaxComputeWorkGroupSize[0] = %u\n", limits->maxComputeWorkGroupSize[0] ); 1185 printf("\t\tmaxComputeWorkGroupSize[1] = %u\n", limits->maxComputeWorkGroupSize[1] ); 1186 printf("\t\tmaxComputeWorkGroupSize[2] = %u\n", limits->maxComputeWorkGroupSize[2] ); 1187 printf("\t\tsubPixelPrecisionBits = %u\n", limits->subPixelPrecisionBits ); 1188 printf("\t\tsubTexelPrecisionBits = %u\n", limits->subTexelPrecisionBits ); 1189 printf("\t\tmipmapPrecisionBits = %u\n", limits->mipmapPrecisionBits ); 1190 printf("\t\tmaxDrawIndexedIndexValue = %u\n", limits->maxDrawIndexedIndexValue ); 1191 printf("\t\tmaxDrawIndirectCount = %u\n", limits->maxDrawIndirectCount ); 1192 printf("\t\tmaxSamplerLodBias = %f\n", limits->maxSamplerLodBias ); 1193 printf("\t\tmaxSamplerAnisotropy = %f\n", limits->maxSamplerAnisotropy ); 1194 printf("\t\tmaxViewports = %u\n", limits->maxViewports ); 1195 printf("\t\tmaxViewportDimensions[0] = %u\n", limits->maxViewportDimensions[0] ); 1196 printf("\t\tmaxViewportDimensions[1] = %u\n", limits->maxViewportDimensions[1] ); 1197 printf("\t\tviewportBoundsRange[0] =%13f\n", limits->viewportBoundsRange[0] ); 1198 printf("\t\tviewportBoundsRange[1] =%13f\n", limits->viewportBoundsRange[1] ); 1199 printf("\t\tviewportSubPixelBits = %u\n", limits->viewportSubPixelBits ); 1200 printf("\t\tminMemoryMapAlignment = " PRINTF_SIZE_T_SPECIFIER "\n", limits->minMemoryMapAlignment ); 1201 printf("\t\tminTexelBufferOffsetAlignment = 0x%" PRIxLEAST64 "\n", limits->minTexelBufferOffsetAlignment ); 1202 printf("\t\tminUniformBufferOffsetAlignment = 0x%" PRIxLEAST64 "\n", limits->minUniformBufferOffsetAlignment ); 1203 printf("\t\tminStorageBufferOffsetAlignment = 0x%" PRIxLEAST64 "\n", limits->minStorageBufferOffsetAlignment ); 1204 printf("\t\tminTexelOffset =%3d\n", limits->minTexelOffset ); 1205 printf("\t\tmaxTexelOffset =%3d\n", limits->maxTexelOffset ); 1206 printf("\t\tminTexelGatherOffset =%3d\n", limits->minTexelGatherOffset ); 1207 printf("\t\tmaxTexelGatherOffset =%3d\n", limits->maxTexelGatherOffset ); 1208 printf("\t\tminInterpolationOffset =%9f\n", limits->minInterpolationOffset ); 1209 printf("\t\tmaxInterpolationOffset =%9f\n", limits->maxInterpolationOffset ); 1210 printf("\t\tsubPixelInterpolationOffsetBits = %u\n", limits->subPixelInterpolationOffsetBits ); 1211 printf("\t\tmaxFramebufferWidth = %u\n", limits->maxFramebufferWidth ); 1212 printf("\t\tmaxFramebufferHeight = %u\n", limits->maxFramebufferHeight ); 1213 printf("\t\tmaxFramebufferLayers = %u\n", limits->maxFramebufferLayers ); 1214 printf("\t\tframebufferColorSampleCounts = %u\n", limits->framebufferColorSampleCounts ); 1215 printf("\t\tframebufferDepthSampleCounts = %u\n", limits->framebufferDepthSampleCounts ); 1216 printf("\t\tframebufferStencilSampleCounts = %u\n", limits->framebufferStencilSampleCounts ); 1217 printf("\t\tframebufferNoAttachmentsSampleCounts = %u\n", limits->framebufferNoAttachmentsSampleCounts ); 1218 printf("\t\tmaxColorAttachments = %u\n", limits->maxColorAttachments ); 1219 printf("\t\tsampledImageColorSampleCounts = %u\n", limits->sampledImageColorSampleCounts ); 1220 printf("\t\tsampledImageDepthSampleCounts = %u\n", limits->sampledImageDepthSampleCounts ); 1221 printf("\t\tsampledImageStencilSampleCounts = %u\n", limits->sampledImageStencilSampleCounts ); 1222 printf("\t\tsampledImageIntegerSampleCounts = %u\n", limits->sampledImageIntegerSampleCounts ); 1223 printf("\t\tstorageImageSampleCounts = %u\n", limits->storageImageSampleCounts ); 1224 printf("\t\tmaxSampleMaskWords = %u\n", limits->maxSampleMaskWords ); 1225 printf("\t\ttimestampComputeAndGraphics = %u\n", limits->timestampComputeAndGraphics ); 1226 printf("\t\ttimestampPeriod = %f\n", limits->timestampPeriod ); 1227 printf("\t\tmaxClipDistances = %u\n", limits->maxClipDistances ); 1228 printf("\t\tmaxCullDistances = %u\n", limits->maxCullDistances ); 1229 printf("\t\tmaxCombinedClipAndCullDistances = %u\n", limits->maxCombinedClipAndCullDistances ); 1230 printf("\t\tdiscreteQueuePriorities = %u\n", limits->discreteQueuePriorities ); 1231 printf("\t\tpointSizeRange[0] = %f\n", limits->pointSizeRange[0] ); 1232 printf("\t\tpointSizeRange[1] = %f\n", limits->pointSizeRange[1] ); 1233 printf("\t\tlineWidthRange[0] = %f\n", limits->lineWidthRange[0] ); 1234 printf("\t\tlineWidthRange[1] = %f\n", limits->lineWidthRange[1] ); 1235 printf("\t\tpointSizeGranularity = %f\n", limits->pointSizeGranularity ); 1236 printf("\t\tlineWidthGranularity = %f\n", limits->lineWidthGranularity ); 1237 printf("\t\tstrictLines = %u\n", limits->strictLines ); 1238 printf("\t\tstandardSampleLocations = %u\n", limits->standardSampleLocations ); 1239 printf("\t\toptimalBufferCopyOffsetAlignment = 0x%" PRIxLEAST64 "\n", limits->optimalBufferCopyOffsetAlignment ); 1240 printf("\t\toptimalBufferCopyRowPitchAlignment = 0x%" PRIxLEAST64 "\n", limits->optimalBufferCopyRowPitchAlignment ); 1241 printf("\t\tnonCoherentAtomSize = 0x%" PRIxLEAST64 "\n", limits->nonCoherentAtomSize ); 1242} 1243 1244static void app_gpu_dump_props(const struct app_gpu *gpu) 1245{ 1246 const VkPhysicalDeviceProperties *props = &gpu->props; 1247 const uint32_t apiVersion=props->apiVersion; 1248 const uint32_t major = VK_VERSION_MAJOR(apiVersion); 1249 const uint32_t minor = VK_VERSION_MINOR(apiVersion); 1250 const uint32_t patch = VK_VERSION_PATCH(apiVersion); 1251 1252 printf("VkPhysicalDeviceProperties:\n"); 1253 printf("===========================\n"); 1254 printf("\tapiVersion = 0x%" PRIxLEAST32 " (%d.%d.%d)\n", apiVersion, major, minor, patch); 1255 printf("\tdriverVersion = %u (0x%" PRIxLEAST32 ")\n",props->driverVersion, props->driverVersion); 1256 printf("\tvendorID = 0x%04x\n", props->vendorID); 1257 printf("\tdeviceID = 0x%04x\n", props->deviceID); 1258 printf("\tdeviceType = %s\n", vk_physical_device_type_string(props->deviceType)); 1259 printf("\tdeviceName = %s\n", props->deviceName); 1260 1261 app_dump_limits(&gpu->props.limits); 1262 app_dump_sparse_props(&gpu->props.sparseProperties); 1263 1264 fflush(stdout); 1265} 1266// clang-format on 1267 1268static void 1269app_dump_extensions(const char *indent, const char *layer_name, 1270 const uint32_t extension_count, 1271 const VkExtensionProperties *extension_properties) { 1272 uint32_t i; 1273 if (layer_name && (strlen(layer_name) > 0)) { 1274 printf("%s%s Extensions", indent, layer_name); 1275 } else { 1276 printf("Extensions"); 1277 } 1278 printf("\tcount = %d\n", extension_count); 1279 for (i = 0; i < extension_count; i++) { 1280 VkExtensionProperties const *ext_prop = &extension_properties[i]; 1281 1282 printf("%s\t", indent); 1283 printf("%-32s: extension revision %2d\n", ext_prop->extensionName, 1284 ext_prop->specVersion); 1285 } 1286 printf("\n"); 1287 fflush(stdout); 1288} 1289 1290static void app_gpu_dump_queue_props(const struct app_gpu *gpu, uint32_t id) { 1291 const VkQueueFamilyProperties *props = &gpu->queue_props[id]; 1292 1293 printf("VkQueueFamilyProperties[%d]:\n", id); 1294 printf("===========================\n"); 1295 char *sep = ""; // separator character 1296 printf("\tqueueFlags = "); 1297 if (props->queueFlags & VK_QUEUE_GRAPHICS_BIT) { 1298 printf("GRAPHICS"); 1299 sep = " | "; 1300 } 1301 if (props->queueFlags & VK_QUEUE_COMPUTE_BIT) { 1302 printf("%sCOMPUTE", sep); 1303 sep = " | "; 1304 } 1305 if (props->queueFlags & VK_QUEUE_TRANSFER_BIT) { 1306 printf("%sTRANSFER", sep); 1307 sep = " | "; 1308 } 1309 if (props->queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) { 1310 printf("%sSPARSE", sep); 1311 } 1312 printf("\n"); 1313 1314 printf("\tqueueCount = %u\n", props->queueCount); 1315 printf("\ttimestampValidBits = %u\n", props->timestampValidBits); 1316 printf("\tminImageTransferGranularity = (%d, %d, %d)\n", 1317 props->minImageTransferGranularity.width, 1318 props->minImageTransferGranularity.height, 1319 props->minImageTransferGranularity.depth); 1320 fflush(stdout); 1321} 1322 1323static void app_gpu_dump_memory_props(const struct app_gpu *gpu) { 1324 const VkPhysicalDeviceMemoryProperties *props = &gpu->memory_props; 1325 1326 printf("VkPhysicalDeviceMemoryProperties:\n"); 1327 printf("=================================\n"); 1328 printf("\tmemoryTypeCount = %u\n", props->memoryTypeCount); 1329 for (uint32_t i = 0; i < props->memoryTypeCount; i++) { 1330 printf("\tmemoryTypes[%u] : \n", i); 1331 printf("\t\theapIndex = %u\n", props->memoryTypes[i].heapIndex); 1332 printf("\t\tpropertyFlags = 0x%" PRIxLEAST32 ":\n", 1333 props->memoryTypes[i].propertyFlags); 1334 1335 // Print each named flag, if it is set. 1336 VkFlags flags = props->memoryTypes[i].propertyFlags; 1337#define PRINT_FLAG(FLAG) \ 1338 if (flags & FLAG) \ 1339 printf("\t\t\t" #FLAG "\n"); 1340 PRINT_FLAG(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) 1341 PRINT_FLAG(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) 1342 PRINT_FLAG(VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) 1343 PRINT_FLAG(VK_MEMORY_PROPERTY_HOST_CACHED_BIT) 1344 PRINT_FLAG(VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) 1345#undef PRINT_FLAG 1346 } 1347 printf("\n"); 1348 printf("\tmemoryHeapCount = %u\n", props->memoryHeapCount); 1349 for (uint32_t i = 0; i < props->memoryHeapCount; i++) { 1350 printf("\tmemoryHeaps[%u] : \n", i); 1351 const VkDeviceSize memSize = props->memoryHeaps[i].size; 1352 printf("\t\tsize = " PRINTF_SIZE_T_SPECIFIER 1353 " (0x%" PRIxLEAST64 ")\n", 1354 (size_t)memSize, memSize); 1355 1356 VkMemoryHeapFlags heapFlags = props->memoryHeaps[i].flags; 1357 printf("\t\tflags: \n\t\t\t"); 1358 printf((heapFlags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) 1359 ? "VK_MEMORY_HEAP_DEVICE_LOCAL_BIT\n" 1360 : "None\n"); 1361 } 1362 fflush(stdout); 1363} 1364 1365static void app_gpu_dump(const struct app_gpu *gpu) { 1366 uint32_t i; 1367 1368 printf("Device Extensions and layers:\n"); 1369 printf("=============================\n"); 1370 printf("GPU%u\n", gpu->id); 1371 app_gpu_dump_props(gpu); 1372 printf("\n"); 1373 app_dump_extensions("", "Device", gpu->device_extension_count, 1374 gpu->device_extensions); 1375 printf("\n"); 1376 printf("Layers\tcount = %d\n", gpu->device_layer_count); 1377 for (uint32_t i = 0; i < gpu->device_layer_count; i++) { 1378 uint32_t major, minor, patch; 1379 char spec_version[64], layer_version[64]; 1380 struct layer_extension_list const *layer_info = &gpu->device_layers[i]; 1381 1382 extract_version(layer_info->layer_properties.specVersion, &major, 1383 &minor, &patch); 1384 snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", major, minor, 1385 patch); 1386 snprintf(layer_version, sizeof(layer_version), "%d", 1387 layer_info->layer_properties.implementationVersion); 1388 printf("\t%s (%s) Vulkan version %s, layer version %s\n", 1389 layer_info->layer_properties.layerName, 1390 (char *)layer_info->layer_properties.description, spec_version, 1391 layer_version); 1392 1393 app_dump_extensions("\t", layer_info->layer_properties.layerName, 1394 layer_info->extension_count, 1395 layer_info->extension_properties); 1396 fflush(stdout); 1397 } 1398 printf("\n"); 1399 for (i = 0; i < gpu->queue_count; i++) { 1400 app_gpu_dump_queue_props(gpu, i); 1401 printf("\n"); 1402 } 1403 app_gpu_dump_memory_props(gpu); 1404 printf("\n"); 1405 app_gpu_dump_features(gpu); 1406 printf("\n"); 1407 app_dev_dump(&gpu->dev); 1408} 1409 1410#ifdef _WIN32 1411// Enlarges the console window to have a large scrollback size. 1412static void ConsoleEnlarge() { 1413 HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); 1414 1415 // make the console window bigger 1416 CONSOLE_SCREEN_BUFFER_INFO csbi; 1417 COORD bufferSize; 1418 if (GetConsoleScreenBufferInfo(consoleHandle, &csbi)) { 1419 bufferSize.X = csbi.dwSize.X + 30; 1420 bufferSize.Y = 20000; 1421 SetConsoleScreenBufferSize(consoleHandle, bufferSize); 1422 } 1423 1424 SMALL_RECT r; 1425 r.Left = r.Top = 0; 1426 r.Right = csbi.dwSize.X - 1 + 30; 1427 r.Bottom = 50; 1428 SetConsoleWindowInfo(consoleHandle, true, &r); 1429 1430 // change the console window title 1431 SetConsoleTitle(TEXT(APP_SHORT_NAME)); 1432} 1433#endif 1434 1435int main(int argc, char **argv) { 1436 unsigned int major, minor, patch; 1437 struct app_gpu gpus[MAX_GPUS]; 1438 VkPhysicalDevice objs[MAX_GPUS]; 1439 uint32_t gpu_count, i; 1440 VkResult err; 1441 struct app_instance inst; 1442 1443#ifdef _WIN32 1444 if (ConsoleIsExclusive()) 1445 ConsoleEnlarge(); 1446#endif 1447 1448 major = VK_VERSION_MAJOR(VK_API_VERSION_1_0); 1449 minor = VK_VERSION_MINOR(VK_API_VERSION_1_0); 1450 patch = VK_VERSION_PATCH(VK_HEADER_VERSION); 1451 1452 printf("===========\n"); 1453 printf("VULKAN INFO\n"); 1454 printf("===========\n\n"); 1455 printf("Vulkan API Version: %d.%d.%d\n\n", major, minor, patch); 1456 1457 app_create_instance(&inst); 1458 1459 printf("Instance Extensions and layers:\n"); 1460 printf("===============================\n"); 1461 app_dump_extensions("", "Instance", inst.global_extension_count, 1462 inst.global_extensions); 1463 1464 printf("Instance Layers\tcount = %d\n", inst.global_layer_count); 1465 for (uint32_t i = 0; i < inst.global_layer_count; i++) { 1466 uint32_t major, minor, patch; 1467 char spec_version[64], layer_version[64]; 1468 VkLayerProperties const *layer_prop = 1469 &inst.global_layers[i].layer_properties; 1470 1471 extract_version(layer_prop->specVersion, &major, &minor, &patch); 1472 snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", major, minor, 1473 patch); 1474 snprintf(layer_version, sizeof(layer_version), "%d", 1475 layer_prop->implementationVersion); 1476 printf("\t%s (%s) Vulkan version %s, layer version %s\n", 1477 layer_prop->layerName, (char *)layer_prop->description, 1478 spec_version, layer_version); 1479 1480 app_dump_extensions("\t", 1481 inst.global_layers[i].layer_properties.layerName, 1482 inst.global_layers[i].extension_count, 1483 inst.global_layers[i].extension_properties); 1484 } 1485 1486 err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, NULL); 1487 if (err) 1488 ERR_EXIT(err); 1489 if (gpu_count > MAX_GPUS) { 1490 printf("Too many GPUS found \n"); 1491 ERR_EXIT(-1); 1492 } 1493 err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, objs); 1494 if (err) 1495 ERR_EXIT(err); 1496 1497 for (i = 0; i < gpu_count; i++) { 1498 app_gpu_init(&gpus[i], i, objs[i]); 1499 app_gpu_dump(&gpus[i]); 1500 printf("\n\n"); 1501 } 1502 1503 printf("Presentable Surface formats:\n"); 1504 printf("============================\n"); 1505 inst.width = 256; 1506 inst.height = 256; 1507 int formatCount = 0; 1508 1509//--WIN32-- 1510#ifdef VK_USE_PLATFORM_WIN32_KHR 1511 app_create_win32_window(&inst); 1512 for (i = 0; i < gpu_count; i++) { 1513 app_create_win32_surface(&inst, &gpus[i]); 1514 printf("GPU id : %u (%s)\n", i, gpus[i].props.deviceName); 1515 printf("Surface type : %s\n", VK_KHR_WIN32_SURFACE_EXTENSION_NAME); 1516 formatCount += app_dump_surface_formats(&inst, &gpus[i]); 1517 app_destroy_surface(&inst); 1518 } 1519 app_destroy_win32_window(&inst); 1520#endif 1521//--XCB-- 1522#ifdef VK_USE_PLATFORM_XCB_KHR 1523 app_create_xcb_window(&inst); 1524 for (i = 0; i < gpu_count; i++) { 1525 app_create_xcb_surface(&inst, &gpus[i]); 1526 printf("GPU id : %u (%s)\n", i, gpus[i].props.deviceName); 1527 printf("Surface type : %s\n", VK_KHR_XCB_SURFACE_EXTENSION_NAME); 1528 formatCount += app_dump_surface_formats(&inst, &gpus[i]); 1529 app_destroy_surface(&inst); 1530 } 1531 app_destroy_xcb_window(&inst); 1532#endif 1533//--XLIB-- 1534#ifdef VK_USE_PLATFORM_XLIB_KHR 1535 app_create_xlib_window(&inst); 1536 for (i = 0; i < gpu_count; i++) { 1537 app_create_xlib_surface(&inst, &gpus[i]); 1538 printf("GPU id : %u (%s)\n", i, gpus[i].props.deviceName); 1539 printf("Surface type : %s\n", VK_KHR_XLIB_SURFACE_EXTENSION_NAME); 1540 formatCount += app_dump_surface_formats(&inst, &gpus[i]); 1541 app_destroy_surface(&inst); 1542 } 1543 app_destroy_xlib_window(&inst); 1544#endif 1545 // TODO: Android / Wayland / MIR 1546 if (!formatCount) 1547 printf("None found\n"); 1548 //--------- 1549 1550 for (i = 0; i < gpu_count; i++) 1551 app_gpu_destroy(&gpus[i]); 1552 1553 app_destroy_instance(&inst); 1554 1555 fflush(stdout); 1556#ifdef _WIN32 1557 if (ConsoleIsExclusive()) 1558 Sleep(INFINITE); 1559#endif 1560 1561 return 0; 1562} 1563