vulkanHppMinimalExample
vulkanHppMinimalExample copied to clipboard
physicalDevice selection issue
Was compiling a few vulkan tutorials I found on the web and came across yours. Line 73-76 in main.cpp:
auto physicalDevice = physicalDevices[std::distance(physicalDevices.begin(),
std::find_if(physicalDevices.begin(), physicalDevices.end(), [](const vk::PhysicalDevice& physicalDevice) {
return strstr(physicalDevice.getProperties().deviceName, "Intel");
}))];
This crashes the program with a 'vector subscript out of range' when there's only one device in the enumeration and it doesn't matchs the substring you've defined ("Intel").
Built with cmake + ninja in VS2022 on Windows 10v19044.2846, with an nVidia 1070 using driver version 528.33. Just selecting the first physical device using auto physicalDevice = physicalDevices[0] was a workaround for this system, which only enumerates a single physical device (the 1070).
It seems to be an intended feature, if you want to just pick the first dedicated gpu with fallback, this is my favoured solution:
std::vector<vk::PhysicalDevice> physicalDevices = instance->enumeratePhysicalDevices();
physicalDevice = physicalDevices[0]; // Pick first device
for (int i = 0; i < physicalDevices.size(); i++) {
if (physicalDevices[i].getProperties().deviceType == vk::PhysicalDeviceType::eDiscreteGpu) {
physicalDevice = physicalDevices[i]; // Only override if a discrete gpu is found
}
}