vulkan/device_select: force default device if environment variable set

Force default device if MESA_VK_DEVICE_SELECT_FORCE_DEFAULT_DEVICE
environment variable set. This will not give multiple device
options to app. There are apps that selects gpu to use based on its
own criteria, this patch can force default behaviour for these apps
by giving only one gpu device to select from.

v2: return 0 if no physical device present (Mihai Preda)
v3: document environment variables (Mihai Preda)(Marek Olšák)

Signed-off-by: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Reviewed-by: Mihai Preda <mhpreda@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15585>
This commit is contained in:
prashanth 2022-03-26 00:01:44 +05:30 committed by Marge Bot
parent 201b0b6d29
commit 09e4fd1d84
2 changed files with 18 additions and 0 deletions

View File

@ -437,6 +437,19 @@ DRI environment variables
disable MSAA for GLX/EGL MSAA visuals
Vulkan mesa device select layer environment variables
-----------------------------------------------------
:envvar:`MESA_VK_DEVICE_SELECT`
when set to "list" prints the list of devices.
when set to "vid:did" number from pci device. That pci device is
selected as default. The default device is returned as the first
device in vkEnumeratePhysicalDevices api.
:envvar:`MESA_VK_DEVICE_SELECT_FORCE_DEFAULT_DEVICE`
when set to 1, the device identified as default will be the only
one returned in vkEnumeratePhysicalDevices api.
EGL environment variables
-------------------------

View File

@ -528,6 +528,11 @@ static VkResult device_select_EnumeratePhysicalDevices(VkInstance instance,
assert(result == VK_SUCCESS);
/* do not give multiple device option to app if force default device */
const char *force_default_device = getenv("MESA_VK_DEVICE_SELECT_FORCE_DEFAULT_DEVICE");
if (force_default_device && !strcmp(force_default_device, "1") && selected_physical_device_count != 0)
selected_physical_device_count = 1;
for (unsigned i = 0; i < selected_physical_device_count; i++) {
vk_outarray_append_typed(VkPhysicalDevice, &out, ent) {
*ent = selected_physical_devices[i];