Select a GPU to use and query its capabilities
| 536 | |
| 537 | // Select a GPU to use and query its capabilities |
| 538 | void setupPhysicalDevice() |
| 539 | { |
| 540 | // Last sanity check |
| 541 | if (!vkEnumeratePhysicalDevices || !vkCreateDevice || !vkGetPhysicalDeviceProperties) |
| 542 | { |
| 543 | vulkanAvailable = false; |
| 544 | return; |
| 545 | } |
| 546 | |
| 547 | // Retrieve list of GPUs |
| 548 | std::uint32_t objectCount = 0; |
| 549 | |
| 550 | std::vector<VkPhysicalDevice> devices; |
| 551 | |
| 552 | if (vkEnumeratePhysicalDevices(instance, &objectCount, nullptr) != VK_SUCCESS) |
| 553 | { |
| 554 | vulkanAvailable = false; |
| 555 | return; |
| 556 | } |
| 557 | |
| 558 | devices.resize(objectCount); |
| 559 | |
| 560 | if (vkEnumeratePhysicalDevices(instance, &objectCount, devices.data()) != VK_SUCCESS) |
| 561 | { |
| 562 | vulkanAvailable = false; |
| 563 | return; |
| 564 | } |
| 565 | |
| 566 | VkPhysicalDeviceType deviceType = VK_PHYSICAL_DEVICE_TYPE_OTHER; |
| 567 | |
| 568 | // Look for a GPU that supports swapchains |
| 569 | for (VkPhysicalDevice dev : devices) |
| 570 | { |
| 571 | VkPhysicalDeviceProperties deviceProperties; |
| 572 | vkGetPhysicalDeviceProperties(dev, &deviceProperties); |
| 573 | |
| 574 | std::vector<VkExtensionProperties> extensions; |
| 575 | |
| 576 | if (vkEnumerateDeviceExtensionProperties(dev, nullptr, &objectCount, nullptr) != VK_SUCCESS) |
| 577 | { |
| 578 | vulkanAvailable = false; |
| 579 | return; |
| 580 | } |
| 581 | |
| 582 | extensions.resize(objectCount); |
| 583 | |
| 584 | if (vkEnumerateDeviceExtensionProperties(dev, nullptr, &objectCount, extensions.data()) != VK_SUCCESS) |
| 585 | { |
| 586 | vulkanAvailable = false; |
| 587 | return; |
| 588 | } |
| 589 | |
| 590 | bool supportsSwapchain = false; |
| 591 | |
| 592 | for (VkExtensionProperties& extension : extensions) |
| 593 | { |
| 594 | if (std::string_view(extension.extensionName) == VK_KHR_SWAPCHAIN_EXTENSION_NAME) |
| 595 | { |
nothing calls this directly
no test coverage detected