'Why does the same device appear twice vulkan

When I enumerate Vulkan devices, I get this list:

## Found 4 devices:

name=NVIDIA GeForce GTX 1060 6GB; vendor_id=7171; uuid=1e6cc8a66603139184fd2788b6ad0eac; driver_version=1972731904; type=2; api_version=1.2.175
name=llvmpipe (LLVM 12.0.0, 256 bits); vendor_id=0; uuid=76616c2d696d65000000000000000000; driver_version=1; type=4; api_version=1.0.2
name=NVIDIA GeForce GTX 1060 6GB; vendor_id=7171; uuid=1e6cc8a66603139184fd2788b6ad0eac; driver_version=1972731904; type=2; api_version=1.2.175
name=llvmpipe (LLVM 12.0.0, 256 bits); vendor_id=0; uuid=76616c2d696d65000000000000000000; driver_version=1; type=4; api_version=1.0.2

## Found 8 queue families:

device_index=0; family_index=0; queue_flags=15; queue_count=16
device_index=0; family_index=1; queue_flags=12; queue_count=2
device_index=0; family_index=2; queue_flags=14; queue_count=8
device_index=1; family_index=0; queue_flags=7; queue_count=1
device_index=2; family_index=0; queue_flags=15; queue_count=16
device_index=2; family_index=1; queue_flags=12; queue_count=2
device_index=2; family_index=2; queue_flags=14; queue_count=8
device_index=3; family_index=0; queue_flags=7; queue_count=1
    uint32_t dev_count{};
    vkEnumeratePhysicalDevices(instance, &dev_count, nullptr);
    if(dev_count == 0) { throw exception{"collect information about Vulkan devices", "No physical device"}; }
    printf("Found %u devices\n", dev_count);
    std::vector<VkPhysicalDevice> m_devices(dev_count);
    vkEnumeratePhysicalDevices(instance, &dev_count, m_devices.data());
    std::ranges::for_each(m_devices, [](auto const& device) {
        vk_device_info dev_info{};
        dev_info.device = device;
        vkGetPhysicalDeviceProperties(device, &dev_info.properties);
        printf("%s\n", device, to_string(dev_info).c_str());
    });
...

Why do I see the same device twice?



Solution 1:[1]

Without the output of

printf("Found %u devices\n", dev_count);

I cannot really tell the state of that vector before the for_each.


Assuming that vector has duplicates? One way to have unique entries is to do the follow:

auto ret = std::ranges::unique(m_devices);
m_devices.erase(ret.begin(), ret.end()); 
// Now m_devices should hold unique entries

Of course, the above code snippet assumes that VkPhysicalDevice implements the == operator.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman