Skip to content

Commit b6fefa1

Browse files
authored
Improve discrete GPU detection using switcheroo-control (#178)
* Improve discrete GPU detection using switcheroo-control * check for vdiscrete when setting is_discrete
1 parent aa7162e commit b6fefa1

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

libxapp/xapp-gpu-offload-helper.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ process_gpus_property (XAppGpuOffloadHelper *helper,
149149
g_autoptr(GVariant) vname = NULL;
150150
g_autoptr(GVariant) venv = NULL;
151151
g_autoptr(GVariant) vdefault = NULL;
152+
g_autoptr(GVariant) vdiscrete = NULL;
152153
const char *name;
153154
g_autofree const char **env_strv = NULL;
154155
gsize env_len;
155156
gboolean is_default;
157+
gboolean is_discrete;
156158

157159
gpu = g_variant_get_child_value (gpus, i);
158160
if (!gpu || !g_variant_is_of_type (gpu, G_VARIANT_TYPE ("a{s*}")))
@@ -163,6 +165,7 @@ process_gpus_property (XAppGpuOffloadHelper *helper,
163165
vname = g_variant_lookup_value (gpu, "Name", NULL);
164166
venv = g_variant_lookup_value (gpu, "Environment", NULL);
165167
vdefault= g_variant_lookup_value (gpu, "Default", NULL);
168+
vdiscrete = g_variant_lookup_value (gpu, "Discrete", NULL);
166169

167170
if (!vname || !venv)
168171
continue;
@@ -180,6 +183,7 @@ process_gpus_property (XAppGpuOffloadHelper *helper,
180183
}
181184

182185
is_default = vdefault ? g_variant_get_boolean (vdefault) : FALSE;
186+
is_discrete = vdiscrete ? g_variant_get_boolean (vdiscrete) : FALSE;
183187

184188
if (is_default)
185189
{
@@ -191,6 +195,7 @@ process_gpus_property (XAppGpuOffloadHelper *helper,
191195
info->display_name = g_strdup (name);
192196
info->env_strv = g_strdupv ((gchar **) env_strv);
193197
info->is_default = is_default;
198+
info->is_discrete = is_discrete;
194199

195200
infos = g_list_append (infos, info);
196201
}
@@ -625,6 +630,33 @@ xapp_gpu_offload_helper_get_offload_infos (XAppGpuOffloadHelper *helper)
625630
GList *retval = NULL;
626631

627632
GList *l;
633+
634+
// add Default GPU first if its discrete
635+
for (l = helper->gpu_infos; l != NULL; l = l->next)
636+
{
637+
XAppGpuInfo *info = l->data;
638+
639+
if (!info->is_default)
640+
continue;
641+
642+
if (info->is_discrete)
643+
retval = g_list_append (retval, info);
644+
break;
645+
}
646+
647+
// add any following discrete GPUs
648+
for (l = helper->gpu_infos; l != NULL; l = l->next)
649+
{
650+
XAppGpuInfo *info = l->data;
651+
652+
if (!info->is_discrete)
653+
continue;
654+
655+
retval = g_list_append (retval, info);
656+
}
657+
658+
// fallback to old behavior
659+
// add non default GPUs to the list
628660
for (l = helper->gpu_infos; l != NULL; l = l->next)
629661
{
630662
XAppGpuInfo *info = l->data;

libxapp/xapp-gpu-offload-helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct _XAppGpuInfo
2626
{
2727
gint id;
2828
gboolean is_default;
29+
gboolean is_discrete;
2930
gchar *display_name;
3031
gchar **env_strv;
3132
};

0 commit comments

Comments
 (0)