Skip to content

Commit

Permalink
Add XAppGpuOffloadHelper.
Browse files Browse the repository at this point in the history
By using switcheroo-control, this will provide broader support for
gpu offloading than relying on magic Ubuntu files.

If switcheroo isn't available, xapp_util_gpu_offload_supported() is
used like before, with default environment variables.
  • Loading branch information
mtwebster committed May 1, 2023
1 parent 2e65c9b commit 5826b7e
Show file tree
Hide file tree
Showing 8 changed files with 843 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/xapp-docs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<title>API reference</title>
<xi:include href="xml/xapp-favorites.xml"/>
<xi:include href="xml/xapp-gtk-window.xml"/>
<xi:include href="xml/xapp-gpu-offload-helper.xml"/>
<xi:include href="xml/xapp-icon-chooser-button.xml"/>
<xi:include href="xml/xapp-icon-chooser-dialog.xml"/>
<xi:include href="xml/xapp-kbd-layout-controller.xml"/>
Expand Down
11 changes: 11 additions & 0 deletions libxapp/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ xapp_debug = [
xapp_headers = [
'xapp-favorites.h',
'xapp-gtk-window.h',
'xapp-gpu-offload-helper.h',
'xapp-icon-chooser-button.h',
'xapp-icon-chooser-dialog.h',
'xapp-monitor-blanker.h',
Expand All @@ -46,6 +47,7 @@ xapp_sources = [
'xapp-favorites.c',
'xapp-glade-catalog.c',
'xapp-gtk-window.c',
'xapp-gpu-offload-helper.c',
'xapp-icon-chooser-button.c',
'xapp-icon-chooser-dialog.c',
'xapp-monitor-blanker.c',
Expand All @@ -58,6 +60,15 @@ xapp_sources = [
'xapp-visibility-group.c'
]

switcheroo_sources = gnome.gdbus_codegen(
'xapp-switcheroo-interface',
sources: 'net.hadess.SwitcherooControl.xml',
interface_prefix: 'net.hadess',
namespace: 'XApp'
)

xapp_sources += switcheroo_sources

if not app_lib_only
libdeps += dependency('libgnomekbdui', required: true)
xapp_headers += 'xapp-kbd-layout-controller.h'
Expand Down
46 changes: 46 additions & 0 deletions libxapp/net.hadess.SwitcherooControl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http:https://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">

<node>

<!--
net.hadess.SwitcherooControl:
@short_description: D-Bus proxy to access dual-GPU controls.
After checking the availability of two switchable GPUs in the machine,
check the value of net.hadess.SwitcherooControl.HasDualGpu to see
if running applications on the discrete GPU should be offered.
The object path will be "/net/hadess/SwitcherooControl".
-->
<interface name="net.hadess.SwitcherooControl">
<!--
HasDualGpu:
Whether two switchable GPUs are present on the system. This property
has been obsoleted in favour of the "NumGPUs" property.
-->
<property name="HasDualGpu" type="b" access="read"/>

<!--
NumGPUs:
The number of GPUs available on the system. Note that while having no
GPUs is unlikely, consumers of this API should probably not throw errors
if that were the case.
-->
<property name="NumGPUs" type="u" access="read"/>

<!--
GPUs:
An array of key-pair values representing each GPU. The key named "Name" (s)
will contain a user-facing name for the GPU, the "Environment" (as) key will
contain an array of even number of strings, each being an environment
variable to set to use the GPU, followed by its value, the "Default" (b) key
will tag the default (usually integrated) GPU.
-->
<property name="GPUs" type="aa{sv}" access="read"/>

</interface>
</node>
3 changes: 3 additions & 0 deletions libxapp/xapp-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static GDebugKey keys[] = {
{ "SnWatcher", XAPP_DEBUG_SN_WATCHER },
{ "GtkModule", XAPP_DEBUG_MODULE},
{ "VisibilityGroup", XAPP_DEBUG_VISIBILITY_GROUP},
{ "GpuOffload", XAPP_DEBUG_GPU_OFFLOAD},
{ 0, }
};

Expand All @@ -61,6 +62,8 @@ debug_flag_to_string (DebugFlags flag)
return "GtkModule";
case XAPP_DEBUG_VISIBILITY_GROUP:
return "VisibilityGroup";
case XAPP_DEBUG_GPU_OFFLOAD:
return "GpuOffload";
}
return "";
}
Expand Down
3 changes: 2 additions & 1 deletion libxapp/xapp-debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ typedef enum
XAPP_DEBUG_STATUS_ICON = 1 << 4,
XAPP_DEBUG_SN_WATCHER = 1 << 5,
XAPP_DEBUG_MODULE = 1 << 6,
XAPP_DEBUG_VISIBILITY_GROUP = 1 << 7
XAPP_DEBUG_VISIBILITY_GROUP = 1 << 7,
XAPP_DEBUG_GPU_OFFLOAD = 1 << 8
} DebugFlags;

void xapp_debug_set_flags (DebugFlags flags);
Expand Down
Loading

0 comments on commit 5826b7e

Please sign in to comment.