Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

physicalDevice selection issue #2

Open
joeholley opened this issue Apr 28, 2023 · 1 comment
Open

physicalDevice selection issue #2

joeholley opened this issue Apr 28, 2023 · 1 comment

Comments

@joeholley
Copy link

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).

@ka-iden
Copy link

ka-iden commented Dec 28, 2024

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
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants