| 1556 | |
| 1557 | template <vkb::BindingType bindingType> |
| 1558 | inline void VulkanSample<bindingType>::select_physical_device() |
| 1559 | { |
| 1560 | assert(instance && "Instance must be created before selecting a physical device"); |
| 1561 | |
| 1562 | std::vector<vk::PhysicalDevice> physical_devices = instance->get_handle().enumeratePhysicalDevices(); |
| 1563 | if (physical_devices.empty()) |
| 1564 | { |
| 1565 | throw std::runtime_error("Couldn't find a physical device that supports Vulkan."); |
| 1566 | } |
| 1567 | |
| 1568 | // A GPU can be explicitly selected via the command line (see plugins/gpu_selection.cpp), this overrides the below GPU selection algorithm |
| 1569 | auto physical_devices_it = physical_devices.begin(); |
| 1570 | if (selected_gpu_index != ~0) |
| 1571 | { |
| 1572 | LOGI("Explicitly selecting GPU {}", selected_gpu_index); |
| 1573 | if (selected_gpu_index > physical_devices.size() - 1) |
| 1574 | { |
| 1575 | throw std::runtime_error("Selected GPU index is not within no. of available GPUs"); |
| 1576 | } |
| 1577 | physical_devices_it = physical_devices.begin() + selected_gpu_index; |
| 1578 | } |
| 1579 | else |
| 1580 | { |
| 1581 | std::vector<size_t> gpu_scores; |
| 1582 | gpu_scores.reserve(physical_devices.size()); |
| 1583 | for (auto const &physical_device : physical_devices) |
| 1584 | { |
| 1585 | if constexpr (bindingType == BindingType::Cpp) |
| 1586 | { |
| 1587 | gpu_scores.push_back(determine_physical_device_score(physical_device)); |
| 1588 | } |
| 1589 | else |
| 1590 | { |
| 1591 | gpu_scores.push_back(determine_physical_device_score(reinterpret_cast<VkPhysicalDevice const &>(physical_device))); |
| 1592 | } |
| 1593 | } |
| 1594 | auto max_score_it = std::ranges::max_element(gpu_scores); |
| 1595 | physical_devices_it = physical_devices.begin() + std::distance(gpu_scores.begin(), max_score_it); |
| 1596 | } |
| 1597 | |
| 1598 | physical_device = std::make_unique<vkb::core::PhysicalDeviceCpp>(*instance, *physical_devices_it); |
| 1599 | } |
| 1600 | |
| 1601 | template <vkb::BindingType bindingType> |
| 1602 | inline void VulkanSample<bindingType>::set_high_priority_graphics_queue_enable(bool enable) |
nothing calls this directly
no test coverage detected