KhronosGroup / KhronosGroup/Vulkan-Loader

Linux ICD ordering doesn't match the documentation

Open
#1,725 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C
Stars
695
Forks
343
Avg merge
1d 1h
Merged PRs (30d)
17

Description

**Describe the bug**
On a system with multiple Vulkan drivers and multiple ICD files, the [documentation](https://github.com/KhronosGroup/Vulkan-Loader/blob/main/docs/LoaderDriverInterface.md#driver-discovery-on-linux) 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](https://github.com/KhronosGroup/Vulkan-Loader/blob/main/loader/loader.c#L1461) newly found drivers to the list of drivers.

The sort step in [loader_linux.c](https://github.com/KhronosGroup/Vulkan-Loader/blob/main/loader/loader_linux.c#L70) 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.

Contributor guide

Open the contributing guide

Research direction

Start in loader/loader.c at loader_icd_add and compare its driver-list insertion behavior with the documented Linux discovery order in docs/LoaderDriverInterface.md. Read the Linux sorting logic in loader/loader_linux.c and reproduce the VK_LOADER_DEBUG=info output with multiple ICD files. Done means the observed original and sorted orders match the documented search order when drivers expose the same GPU.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.