mirror of
https://github.com/brl/mutter.git
synced 2024-12-24 12:02:04 +00:00
renderer/native: Add udev rule to select primary GPU
Sometimes the automatically selected primary GPU isn't suitable with no way to make an well educated guess to do it better. To make it possible for the user to override the automatically calculated default, make it possible to override it using a udev rule. E.g. to select /dev/dri/card1 as the primary GPU, add a file e.g. /usr/lib/udev/rules.d/61-mutter-primary-gpu.rules (path my vary depending on distribution) containing the fellowing line: ENV{DEVNAME}=="/dev/dri/card1", TAG+="mutter-device-preferred-primary" Reboot or manual triggering of udev rules to make it take effect may be required. Related: https://gitlab.gnome.org/GNOME/mutter/merge_requests/1057 https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1562 Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1562>
This commit is contained in:
parent
83360a4aed
commit
d622960429
@ -373,6 +373,9 @@ create_gpu_from_udev_device (MetaBackendNative *native,
|
||||
if (meta_is_udev_device_requires_modifiers (device))
|
||||
flags |= META_KMS_DEVICE_FLAG_REQUIRES_MODIFIERS;
|
||||
|
||||
if (meta_is_udev_device_preferred_primary (device))
|
||||
flags |= META_KMS_DEVICE_FLAG_PREFERRED_PRIMARY;
|
||||
|
||||
device_path = g_udev_device_get_device_file (device);
|
||||
|
||||
kms_device = meta_kms_create_device (native->kms, device_path, flags,
|
||||
|
@ -57,6 +57,7 @@ typedef enum _MetaKmsDeviceFlag
|
||||
META_KMS_DEVICE_FLAG_BOOT_VGA = 1 << 0,
|
||||
META_KMS_DEVICE_FLAG_PLATFORM_DEVICE = 1 << 1,
|
||||
META_KMS_DEVICE_FLAG_REQUIRES_MODIFIERS = 1 << 2,
|
||||
META_KMS_DEVICE_FLAG_PREFERRED_PRIMARY = 1 << 3,
|
||||
} MetaKmsDeviceFlag;
|
||||
|
||||
typedef enum _MetaKmsPlaneType MetaKmsPlaneType;
|
||||
|
@ -64,6 +64,7 @@
|
||||
#include "backends/native/meta-drm-buffer-import.h"
|
||||
#include "backends/native/meta-drm-buffer.h"
|
||||
#include "backends/native/meta-gpu-kms.h"
|
||||
#include "backends/native/meta-kms-device.h"
|
||||
#include "backends/native/meta-kms-update.h"
|
||||
#include "backends/native/meta-kms-utils.h"
|
||||
#include "backends/native/meta-kms.h"
|
||||
@ -3752,6 +3753,21 @@ choose_primary_gpu_unchecked (MetaBackend *backend,
|
||||
*/
|
||||
for (allow_sw = 0; allow_sw < 2; allow_sw++)
|
||||
{
|
||||
/* First check if one was explicitly configured. */
|
||||
for (l = gpus; l; l = l->next)
|
||||
{
|
||||
MetaGpuKms *gpu_kms = META_GPU_KMS (l->data);
|
||||
MetaKmsDevice *kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
|
||||
|
||||
if (meta_kms_device_get_flags (kms_device) &
|
||||
META_KMS_DEVICE_FLAG_PREFERRED_PRIMARY)
|
||||
{
|
||||
g_message ("GPU %s selected primary given udev rule",
|
||||
meta_gpu_kms_get_file_path (gpu_kms));
|
||||
return gpu_kms;
|
||||
}
|
||||
}
|
||||
|
||||
/* Prefer a platform device */
|
||||
for (l = gpus; l; l = l->next)
|
||||
{
|
||||
@ -3760,8 +3776,12 @@ choose_primary_gpu_unchecked (MetaBackend *backend,
|
||||
if (meta_gpu_kms_is_platform_device (gpu_kms) &&
|
||||
(allow_sw == 1 ||
|
||||
gpu_kms_is_hardware_rendering (renderer_native, gpu_kms)))
|
||||
{
|
||||
g_message ("Integrated GPU %s selected as primary",
|
||||
meta_gpu_kms_get_file_path (gpu_kms));
|
||||
return gpu_kms;
|
||||
}
|
||||
}
|
||||
|
||||
/* Otherwise a device we booted with */
|
||||
for (l = gpus; l; l = l->next)
|
||||
@ -3771,8 +3791,12 @@ choose_primary_gpu_unchecked (MetaBackend *backend,
|
||||
if (meta_gpu_kms_is_boot_vga (gpu_kms) &&
|
||||
(allow_sw == 1 ||
|
||||
gpu_kms_is_hardware_rendering (renderer_native, gpu_kms)))
|
||||
{
|
||||
g_message ("Boot VGA GPU %s selected as primary",
|
||||
meta_gpu_kms_get_file_path (gpu_kms));
|
||||
return gpu_kms;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fall back to any device */
|
||||
for (l = gpus; l; l = l->next)
|
||||
@ -3781,9 +3805,13 @@ choose_primary_gpu_unchecked (MetaBackend *backend,
|
||||
|
||||
if (allow_sw == 1 ||
|
||||
gpu_kms_is_hardware_rendering (renderer_native, gpu_kms))
|
||||
{
|
||||
g_message ("GPU %s selected as primary",
|
||||
meta_gpu_kms_get_file_path (gpu_kms));
|
||||
return gpu_kms;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
|
@ -95,6 +95,18 @@ meta_is_udev_device_requires_modifiers (GUdevDevice *device)
|
||||
return g_strv_contains (tags, "mutter-device-requires-kms-modifiers");
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_is_udev_device_preferred_primary (GUdevDevice *device)
|
||||
{
|
||||
const char * const * tags;
|
||||
|
||||
tags = g_udev_device_get_tags (device);
|
||||
if (!tags)
|
||||
return FALSE;
|
||||
|
||||
return g_strv_contains (tags, "mutter-device-preferred-primary");
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_udev_is_drm_device (MetaUdev *udev,
|
||||
GUdevDevice *device)
|
||||
|
@ -34,6 +34,8 @@ gboolean meta_is_udev_device_boot_vga (GUdevDevice *device);
|
||||
|
||||
gboolean meta_is_udev_device_requires_modifiers (GUdevDevice *device);
|
||||
|
||||
gboolean meta_is_udev_device_preferred_primary (GUdevDevice *device);
|
||||
|
||||
gboolean meta_udev_is_drm_device (MetaUdev *udev,
|
||||
GUdevDevice *device);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user