Vulkan-Loader icon indicating copy to clipboard operation
Vulkan-Loader copied to clipboard

Linux ICD ordering doesn't match the documentation

Open peppsac opened this issue 7 months ago • 2 comments

Describe the bug On a system with multiple Vulkan drivers and multiple ICD files, the documentation specifies the loading order.

As an example, it would pick first the driver manifest from /etc/vulkan/icd.d (say driver1.json), then the one from /usr/share/vulkan/icd.d (driver2.json).

Then using VK_LOADER_DEBUG=info, I can see that:

  • driver1 is loaded first, then driver2
  • but in the Original order and Sorted order logs, driver2 comes first, then driver1 and so applications use driver2.

AFAICT this is caused by loader_icd_add that will prepend newly found drivers to the list of drivers.

The sort step in loader_linux.c doesn't change the order of the 2 drivers - which is expected because the sort is mostly based on the PCI bus information and in my test case both drivers expose the same GPU.

Is this the expected behavior? Or should apps end up using driver1 because its "Search Order" is smaller than driver2's?

Additional Information Tweaking the loader_icd_add function to append newly found driver fixes the issue.

peppsac avatar Jun 10 '25 20:06 peppsac

So the order VkPhysicalDevices appear in is not specified by the Vulkan Specification. The order drivers are discovered is indeed backwards to the order that VkPhysicalDevices are enumerated, at least no layers or the linux sorting routine doesn't alter the order.

I think appending ICD's is appropriate, and makes the logic of the loader a bit easier to follow. I bet the original reason was 'order doesn't matter, prepend is faster than iterating through the whole list to append'. But there's hardly more than 4 drivers on a system at a time in the worst case, so its wouldn't be a performance bottleneck in the slightest.

I will say that making a change to append ICD's will require redoing a lot of the tests where the order of the physical devices is subject to the order drivers are found in. If there is any reason I haven't switched to appending it is due to that body of work which must be done.

charles-lunarg avatar Jun 10 '25 21:06 charles-lunarg

Thanks for the detailed answer.

Some tests are indeed dependent on the ordering, but fixing them is straightforward.

BTW while doing this I think I stumbled on 2 bugs:

  1. https://github.com/KhronosGroup/Vulkan-Loader/blob/main/tests/loader_version_tests.cpp#L1000 this should check for !exclusive as is done in the creation?
  2. The 2 loops are using an incorrect test condition ( i == 0), I believe it should be:
for (int i = (int) xxx_drivers.size() - 1; i >= 0; i--) {

peppsac avatar Jun 24 '25 06:06 peppsac