Compare commits

...

4 Commits

Author SHA1 Message Date
Bastien Nocera
752b1df659 shell-app: Add discrete GPU support for NVidia drivers
Add the necessary environment variables that would make offloading to
the NVidia "secondary" drivers work as expected.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/issues/1810
2019-10-24 14:49:22 +02:00
Bastien Nocera
366b06716d appDisplay: Respect X-KDE-RunOnDiscreteGpu appInfo property
When X-KDE-RunOnDiscreteGpu is set in the application's .desktop file,
launch the application on the discrete GPU if available, and offer
to launch on the discrete GPU manually otherwise.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/issues/1804
2019-10-24 14:44:40 +02:00
Bastien Nocera
4d47b16d33 shell-app: Respect X-KDE-RunOnDiscreteGpu when launching apps
If whether to launch on the discrete GPU or the integrated one isn't
passed down to us, check whether the application prefers to be launched
on the discrete GPU.

See: https://gitlab.gnome.org/GNOME/gnome-shell/issues/1804
2019-10-24 14:44:40 +02:00
Bastien Nocera
6526e9edf6 appDisplay: Remove unimplemented 'activate-discrete-gpu'
It was added in commit 009d021 but not advertised, and likely not used
by an application since then.

See: https://gitlab.gnome.org/GNOME/gnome-shell/issues/1804
2019-10-24 14:22:51 +02:00
3 changed files with 50 additions and 20 deletions

View File

@ -2513,13 +2513,15 @@ var AppIconMenu = class AppIconMenu extends PopupMenu.PopupMenu {
this._appendSeparator();
}
let wantsDiscreteGpu = appInfo.get_boolean("PreferRunOnDiscreteGPU") ||
appInfo.get_boolean("X-KDE-RunOnDiscreteGpu");
if (discreteGpuAvailable &&
this._source.app.state == Shell.AppState.STOPPED &&
!actions.includes('activate-discrete-gpu')) {
!wantsDiscreteGpu &&
this._source.app.state == Shell.AppState.STOPPED) {
this._onDiscreteGpuMenuItem = this._appendMenuItem(_("Launch using Dedicated Graphics Card"));
this._onDiscreteGpuMenuItem.connect('activate', () => {
this._source.animateLaunch();
this._source.app.launch(0, -1, true);
this._source.app.launch(0, -1, Shell.AppGpuSelection.DISCRETE);
this.emit('activate-window', null);
});
}
@ -2528,8 +2530,7 @@ var AppIconMenu = class AppIconMenu extends PopupMenu.PopupMenu {
let action = actions[i];
let item = this._appendMenuItem(appInfo.get_action_name(action));
item.connect('activate', (emitter, event) => {
if (action == 'new-window' ||
action == 'activate-discrete-gpu')
if (action == 'new-window')
this._source.animateLaunch();
this._source.app.launch_action(action, event.get_time(), -1);

View File

@ -509,7 +509,7 @@ shell_app_activate_full (ShellApp *app,
case SHELL_APP_STATE_STOPPED:
{
GError *error = NULL;
if (!shell_app_launch (app, timestamp, workspace, FALSE, &error))
if (!shell_app_launch (app, timestamp, workspace, SHELL_APP_GPU_SELECTION_AUTO, &error))
{
char *msg;
msg = g_strdup_printf (_("Failed to launch “%s”"), shell_app_get_name (app));
@ -584,7 +584,7 @@ shell_app_open_new_window (ShellApp *app,
* instance (Firefox). There are a few less-sensical cases such
* as say Pidgin.
*/
shell_app_launch (app, 0, workspace, FALSE, NULL);
shell_app_launch (app, 0, workspace, SHELL_APP_GPU_SELECTION_AUTO, NULL);
}
/**
@ -1255,19 +1255,37 @@ wait_pid (GDesktopAppInfo *appinfo,
g_child_watch_add (pid, (GChildWatchFunc) g_spawn_close_pid, NULL);
}
static gboolean
get_with_discrete_gpu (ShellApp *app,
ShellAppGpuSelection discrete_gpu)
{
switch (discrete_gpu)
{
case SHELL_APP_GPU_SELECTION_INTEGRATED:
return FALSE;
case SHELL_APP_GPU_SELECTION_DISCRETE:
return TRUE;
case SHELL_APP_GPU_SELECTION_AUTO:
return g_desktop_app_info_get_boolean (app->info, "PreferRunOnDiscreteGPU") ||
g_desktop_app_info_get_boolean (app->info, "X-KDE-RunOnDiscreteGpu");
default:
g_assert_not_reached();
}
}
/**
* shell_app_launch:
* @timestamp: Event timestamp, or 0 for current event timestamp
* @workspace: Start on this workspace, or -1 for default
* @discrete_gpu: Whether to start on the discrete GPU
* @discrete_gpu: the preferred GPU to launch the application on.
* @error: A #GError
*/
gboolean
shell_app_launch (ShellApp *app,
guint timestamp,
int workspace,
gboolean discrete_gpu,
GError **error)
shell_app_launch (ShellApp *app,
guint timestamp,
int workspace,
ShellAppGpuSelection discrete_gpu,
GError **error)
{
ShellGlobal *global;
GAppLaunchContext *context;
@ -1289,8 +1307,13 @@ shell_app_launch (ShellApp *app,
global = shell_global_get ();
context = shell_global_create_app_launch_context (global, timestamp, workspace);
if (discrete_gpu)
g_app_launch_context_setenv (context, "DRI_PRIME", "1");
/* FIXME: this should probably check whether we're on a dual-GPU system */
if (get_with_discrete_gpu (app, discrete_gpu))
{
g_app_launch_context_setenv (context, "DRI_PRIME", "1");
g_app_launch_context_setenv (context, "__NV_PRIME_RENDER_OFFLOAD", "1");
g_app_launch_context_setenv (context, "__GLX_VENDOR_LIBRARY_NAME", "nvidia");
}
/* Set LEAVE_DESCRIPTORS_OPEN in order to use an optimized gspawn
* codepath. The shell's open file descriptors should be marked CLOEXEC

View File

@ -18,6 +18,12 @@ typedef enum {
SHELL_APP_STATE_RUNNING
} ShellAppState;
typedef enum {
SHELL_APP_GPU_SELECTION_AUTO = -1,
SHELL_APP_GPU_SELECTION_INTEGRATED = 0,
SHELL_APP_GPU_SELECTION_DISCRETE = 1
} ShellAppGpuSelection;
const char *shell_app_get_id (ShellApp *app);
GDesktopAppInfo *shell_app_get_app_info (ShellApp *app);
@ -51,11 +57,11 @@ GSList *shell_app_get_pids (ShellApp *app);
gboolean shell_app_is_on_workspace (ShellApp *app, MetaWorkspace *workspace);
gboolean shell_app_launch (ShellApp *app,
guint timestamp,
int workspace,
gboolean discrete_gpu,
GError **error);
gboolean shell_app_launch (ShellApp *app,
guint timestamp,
int workspace,
ShellAppGpuSelection discrete_gpu,
GError **error);
void shell_app_launch_action (ShellApp *app,
const char *action_name,