MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Tools / select_physical_device

Method select_physical_device

cube/cube.cpp:1850–1983  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1848}
1849
1850void Demo::select_physical_device() {
1851 auto physical_device_return = inst.enumeratePhysicalDevices();
1852 VERIFY(physical_device_return.result == vk::Result::eSuccess);
1853 auto physical_devices = physical_device_return.value;
1854
1855 if (physical_devices.size() <= 0) {
1856 ERR_EXIT(
1857 "vkEnumeratePhysicalDevices reported zero accessible devices.\n\n"
1858 "Do you have a compatible Vulkan installable client driver (ICD) installed?\n"
1859 "Please look at the Getting Started guide for additional information.\n",
1860 "vkEnumeratePhysicalDevices Failure");
1861 }
1862
1863 if (invalid_gpu_selection || (gpu_number >= 0 && !(static_cast<uint32_t>(gpu_number) < physical_devices.size()))) {
1864 fprintf(stderr, "GPU %d specified is not present, GPU count = %zu\n", gpu_number, physical_devices.size());
1865 ERR_EXIT("Specified GPU number is not present", "User Error");
1866 }
1867
1868 if (wsi_platform == WsiPlatform::display) {
1869#if defined(VK_USE_PLATFORM_DISPLAY_KHR)
1870 gpu_number = find_display_gpu(gpu_number, physical_devices);
1871 if (gpu_number < 0) {
1872 printf("Cannot find any display!\n");
1873 fflush(stdout);
1874 exit(1);
1875 }
1876#else
1877 printf(
1878 "WSI selection was set to DISPLAY but vkcubepp was not compiled with support for the DISPLAY platform, exiting "
1879 "\n");
1880 fflush(stdout);
1881 exit(1);
1882#endif
1883 } else {
1884 /* Try to auto select most suitable device */
1885 if (gpu_number == -1) {
1886 int prev_priority = 0;
1887 for (uint32_t i = 0; i < physical_devices.size(); i++) {
1888 const auto physicalDeviceProperties = physical_devices[i].getProperties();
1889 assert(physicalDeviceProperties.deviceType <= vk::PhysicalDeviceType::eCpu);
1890
1891 auto support_result = physical_devices[i].getSurfaceSupportKHR(0, surface);
1892 if (support_result.result != vk::Result::eSuccess || support_result.value != vk::True) {
1893 continue;
1894 }
1895
1896 std::map<vk::PhysicalDeviceType, int> device_type_priorities = {
1897 {vk::PhysicalDeviceType::eDiscreteGpu, 5}, {vk::PhysicalDeviceType::eIntegratedGpu, 4},
1898 {vk::PhysicalDeviceType::eVirtualGpu, 3}, {vk::PhysicalDeviceType::eCpu, 2},
1899 {vk::PhysicalDeviceType::eOther, 1},
1900 };
1901 int priority = -1;
1902 if (device_type_priorities.find(physicalDeviceProperties.deviceType) != device_type_priorities.end()) {
1903 priority = device_type_priorities[physicalDeviceProperties.deviceType];
1904 }
1905
1906 if (priority > prev_priority) {
1907 gpu_number = i;

Callers 2

WinMainFunction · 0.80
demo_mainFunction · 0.80

Calls 2

find_display_gpuFunction · 0.70
to_stringFunction · 0.70

Tested by

no test coverage detected