From 4d511e71552b64df7413a50d92abf5d1bc38fc8b Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Fri, 16 Feb 2024 08:18:22 +0100 Subject: [PATCH 1/2] Improve discrete GPU detection using switcheroo-control --- libxapp/xapp-gpu-offload-helper.c | 32 +++++++++++++++++++++++++++++++ libxapp/xapp-gpu-offload-helper.h | 1 + 2 files changed, 33 insertions(+) diff --git a/libxapp/xapp-gpu-offload-helper.c b/libxapp/xapp-gpu-offload-helper.c index a26168f..22ba084 100644 --- a/libxapp/xapp-gpu-offload-helper.c +++ b/libxapp/xapp-gpu-offload-helper.c @@ -149,10 +149,12 @@ process_gpus_property (XAppGpuOffloadHelper *helper, g_autoptr(GVariant) vname = NULL; g_autoptr(GVariant) venv = NULL; g_autoptr(GVariant) vdefault = NULL; + g_autoptr(GVariant) vdiscrete = NULL; const char *name; g_autofree const char **env_strv = NULL; gsize env_len; gboolean is_default; + gboolean is_discrete; gpu = g_variant_get_child_value (gpus, i); if (!gpu || !g_variant_is_of_type (gpu, G_VARIANT_TYPE ("a{s*}"))) @@ -163,6 +165,7 @@ process_gpus_property (XAppGpuOffloadHelper *helper, vname = g_variant_lookup_value (gpu, "Name", NULL); venv = g_variant_lookup_value (gpu, "Environment", NULL); vdefault= g_variant_lookup_value (gpu, "Default", NULL); + vdiscrete = g_variant_lookup_value (gpu, "Discrete", NULL); if (!vname || !venv) continue; @@ -180,6 +183,7 @@ process_gpus_property (XAppGpuOffloadHelper *helper, } is_default = vdefault ? g_variant_get_boolean (vdefault) : FALSE; + is_discrete = vdefault ? g_variant_get_boolean (vdiscrete) : FALSE; if (is_default) { @@ -191,6 +195,7 @@ process_gpus_property (XAppGpuOffloadHelper *helper, info->display_name = g_strdup (name); info->env_strv = g_strdupv ((gchar **) env_strv); info->is_default = is_default; + info->is_discrete = is_discrete; infos = g_list_append (infos, info); } @@ -625,6 +630,33 @@ xapp_gpu_offload_helper_get_offload_infos (XAppGpuOffloadHelper *helper) GList *retval = NULL; GList *l; + + // add Default GPU first if its discrete + for (l = helper->gpu_infos; l != NULL; l = l->next) + { + XAppGpuInfo *info = l->data; + + if (!info->is_default) + continue; + + if (info->is_discrete) + retval = g_list_append (retval, info); + break; + } + + // add any following discrete GPUs + for (l = helper->gpu_infos; l != NULL; l = l->next) + { + XAppGpuInfo *info = l->data; + + if (!info->is_discrete) + continue; + + retval = g_list_append (retval, info); + } + + // fallback to old behavior + // add non default GPUs to the list for (l = helper->gpu_infos; l != NULL; l = l->next) { XAppGpuInfo *info = l->data; diff --git a/libxapp/xapp-gpu-offload-helper.h b/libxapp/xapp-gpu-offload-helper.h index 3b21092..e740b7a 100644 --- a/libxapp/xapp-gpu-offload-helper.h +++ b/libxapp/xapp-gpu-offload-helper.h @@ -26,6 +26,7 @@ struct _XAppGpuInfo { gint id; gboolean is_default; + gboolean is_discrete; gchar *display_name; gchar **env_strv; }; From afd70cd1713f6863dce7fcdff2fe3b88900ff960 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sat, 17 Feb 2024 08:25:34 +0100 Subject: [PATCH 2/2] check for vdiscrete when setting is_discrete --- libxapp/xapp-gpu-offload-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxapp/xapp-gpu-offload-helper.c b/libxapp/xapp-gpu-offload-helper.c index 22ba084..bdb4b0f 100644 --- a/libxapp/xapp-gpu-offload-helper.c +++ b/libxapp/xapp-gpu-offload-helper.c @@ -183,7 +183,7 @@ process_gpus_property (XAppGpuOffloadHelper *helper, } is_default = vdefault ? g_variant_get_boolean (vdefault) : FALSE; - is_discrete = vdefault ? g_variant_get_boolean (vdiscrete) : FALSE; + is_discrete = vdiscrete ? g_variant_get_boolean (vdiscrete) : FALSE; if (is_default) {