mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
Run desktop games on the GPU in a window (#1584)
Steam games and Battle.net started from the KDE desktop run on the GPU in gamescope, opened as a KDE window, and Plasma no longer leaves programs with a zero realtime CPU limit that got games killed.
This commit is contained in:
1 parent
cce742766d
commit
c71ba6da96
9 files changed
+214
-12
No files matched your search
@@ -12,6 +12,9 @@ export MOZ_DISABLE_SOCKET_PROCESS_SANDBOX=1 MOZ_DISABLE_UTILITY_SANDBOX=1
|
||||
export MOZ_SHM_NO_SEALS=1
|
||||
export KWIN_COMPOSE=Q QT_QUICK_BACKEND=software LIBGL_ALWAYS_SOFTWARE=1 GALLIUM_DRIVER=llvmpipe
|
||||
[ -e /etc/mpv/mpv.conf ] || { mkdir -p /etc/mpv && echo gpu-sw=yes >/etc/mpv/mpv.conf; } 2>/dev/null
|
||||
for conf in client client-rt; do
|
||||
mkdir -p "/etc/pipewire/$conf.conf.d" && printf 'context.properties = {\n module.rt = false\n}\n' >"/etc/pipewire/$conf.conf.d/droiddeck-rt.conf"
|
||||
done 2>/dev/null
|
||||
export DROIDDECK_NESTED_SCALE=1
|
||||
export DROIDDECK_GLTHREAD=${mesa_glthread:-}
|
||||
unset MESA_LOADER_DRIVER_OVERRIDE LIBGL_KOPPER_DRI2 mesa_glthread
|
||||
|
||||
@@ -6,21 +6,42 @@ if [ -n "${BL_DEBUG_DIR:-}" ]; then
|
||||
fi
|
||||
width=${BL_WIDTH:-1280}
|
||||
height=${BL_HEIGHT:-720}
|
||||
args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
window=0
|
||||
if [ "${BL_DESKTOP_GPU_WINDOW:-1}" != 0 ] && [ -n "${WAYLAND_DISPLAY:-}" ] && [ "$WAYLAND_DISPLAY" != wayland-0 ]; then
|
||||
window=1
|
||||
parent=$WAYLAND_DISPLAY
|
||||
args=(--backend sdl --expose-wayland -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
else
|
||||
args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
fi
|
||||
if [ "${BL_FPS:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_FPS")
|
||||
elif [ "${BL_REFRESH:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_REFRESH")
|
||||
fi
|
||||
[ "${BL_HDR:-0}" = 1 ] && args+=(--hdr-enabled)
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): $* (gamescope ${width}x${height} on wayland-0)"
|
||||
export WAYLAND_DISPLAY=wayland-0
|
||||
if [ "$window" = 1 ]; then
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): $* (gamescope ${width}x${height} in a window on $parent)"
|
||||
else
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): $* (gamescope ${width}x${height} on wayland-0)"
|
||||
export WAYLAND_DISPLAY=wayland-0
|
||||
fi
|
||||
export GDK_BACKEND=x11 QT_QPA_PLATFORM=xcb SDL_VIDEODRIVER=x11
|
||||
unset LIBGL_ALWAYS_SOFTWARE QT_QUICK_BACKEND KWIN_COMPOSE
|
||||
wsi=",${MESA_VK_WSI_DEBUG:-},"
|
||||
while [[ $wsi == *,sw,* ]]; do wsi=${wsi//,sw,/,}; done
|
||||
wsi=${wsi#,}; wsi=${wsi%,}
|
||||
if [ -n "$wsi" ]; then export MESA_VK_WSI_DEBUG=$wsi; else unset MESA_VK_WSI_DEBUG; fi
|
||||
export BL_DESKTOP_GPU_CHILD=1
|
||||
export MESA_LOADER_DRIVER_OVERRIDE=zink GALLIUM_DRIVER=zink LIBGL_KOPPER_DRI2=true
|
||||
[ -n "${DROIDDECK_GLTHREAD:-}" ] && export mesa_glthread=$DROIDDECK_GLTHREAD
|
||||
export APPIMAGE_EXTRACT_AND_RUN=1
|
||||
gamescope "${args[@]}" -- /usr/local/bin/droiddeck-gpu-window "$@"
|
||||
if [ "$window" = 1 ]; then
|
||||
export BL_GPU_CHILD_WSI=${MESA_VK_WSI_DEBUG:-}
|
||||
SDL_VIDEODRIVER=wayland MESA_VK_WSI_DEBUG=sw gamescope "${args[@]}" -- /usr/local/bin/droiddeck-gpu-window "$@"
|
||||
else
|
||||
gamescope "${args[@]}" -- /usr/local/bin/droiddeck-gpu-window "$@"
|
||||
fi
|
||||
rc=$?
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): exited $rc"
|
||||
exit $rc
|
||||
@@ -551,8 +551,17 @@ class Tidy:
|
||||
return False
|
||||
|
||||
|
||||
def desktop_gpu():
|
||||
if os.environ.get("BL_DESKTOP") != "1" or os.environ.get("BL_DESKTOP_GPU_CHILD"):
|
||||
return None
|
||||
if os.environ.get("BL_DESKTOP_GPU", "on").strip().lower() in ("off", "0", "no", "false"):
|
||||
return None
|
||||
gpu = os.path.join(BIN, "droiddeck-gpu")
|
||||
return gpu if os.access(gpu, os.X_OK) else None
|
||||
|
||||
|
||||
def proton_options():
|
||||
if os.environ.get("BL_DESKTOP") == "1":
|
||||
if os.environ.get("BL_DESKTOP") == "1" and not os.environ.get("BL_DESKTOP_GPU_CHILD"):
|
||||
return ["--window"]
|
||||
width, height = os.environ.get("BL_WIDTH", ""), os.environ.get("BL_HEIGHT", "")
|
||||
options = ["--desktop", "%sx%s" % (width, height)] if width.isdigit() and height.isdigit() else []
|
||||
@@ -943,6 +952,10 @@ def main(argv):
|
||||
if action == "status":
|
||||
print(json.dumps(status(root)))
|
||||
return 0
|
||||
gpu = desktop_gpu()
|
||||
if gpu:
|
||||
say("the desktop starts Battle.net on the GPU")
|
||||
os.execv(gpu, [gpu, os.path.abspath(sys.argv[0])] + list(sys.argv[1:]))
|
||||
os.environ["BL_BATTLENET"] = "1"
|
||||
if launching:
|
||||
say("launch %s" % argv[1])
|
||||
|
||||
@@ -45,6 +45,13 @@ def advertise_compositing():
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
raise SystemExit('usage: droiddeck-gpu-window <program> [args...]')
|
||||
if 'BL_GPU_CHILD_WSI' in os.environ:
|
||||
wsi = os.environ.pop('BL_GPU_CHILD_WSI')
|
||||
if wsi:
|
||||
os.environ['MESA_VK_WSI_DEBUG'] = wsi
|
||||
else:
|
||||
os.environ.pop('MESA_VK_WSI_DEBUG', None)
|
||||
os.environ['SDL_VIDEODRIVER'] = 'x11'
|
||||
os.environ.setdefault('GTK_CSD', '1')
|
||||
try:
|
||||
connection = advertise_compositing()
|
||||
|
||||
@@ -9,9 +9,9 @@ Add an app does) when that holds native programs or libraries. A Steam library's
|
||||
droiddeck-open --exec FILE [ARGS...] an exec the kernel refused (libblsession)
|
||||
droiddeck-open --install the Run entries and default handlers
|
||||
|
||||
The desktop composites in software, so a program started from it goes full screen on the GPU
|
||||
(droiddeck-gpu), as the menu's games do: --window keeps it in a desktop window instead, --terminal
|
||||
runs it in Konsole. A plain script stays on the desktop, and an exec whose output is read (a terminal,
|
||||
The desktop composites in software, so a program started from it runs on the GPU in a window of its
|
||||
own (droiddeck-gpu), as the menu's games do: --window keeps it on the desktop's software drawing
|
||||
instead, --terminal runs it in Konsole. A plain script stays on the desktop, and an exec whose output is read (a terminal,
|
||||
a pipe, a file) stays where it was started.
|
||||
"""
|
||||
import fcntl
|
||||
@@ -337,7 +337,7 @@ def unattended(env):
|
||||
|
||||
|
||||
def placed(cmd, what, mode, env):
|
||||
"""[cmd] where it shows: full screen on the GPU from the desktop, else where it was started."""
|
||||
"""[cmd] where it shows: on the GPU from the desktop, else where it was started."""
|
||||
if mode == "terminal" and what not in ("windows", "steam") and shutil.which("konsole"):
|
||||
return ["konsole", "--hold", "-e"] + cmd
|
||||
if mode == "window" or what in ("script", "steam") or not on_desktop(env):
|
||||
|
||||
@@ -90,6 +90,34 @@ bl_run() {
|
||||
}
|
||||
"""
|
||||
|
||||
BL_DESKTOP_GPU_SETUP = """
|
||||
bl_desktop_gpu() {
|
||||
local name saved gpu=/usr/local/bin/droiddeck-gpu
|
||||
local names=(LD_PRELOAD LD_LIBRARY_PATH ENABLE_VK_LAYER_VALVE_steam_overlay_1 ENABLE_VK_LAYER_VALVE_steam_fossilize_1)
|
||||
if [ -n "${BL_DESKTOP_GPU_CHILD:-}" ]; then
|
||||
for name in "${names[@]}"; do
|
||||
saved=BL_GPU_SAVED_$name
|
||||
[ -n "${!saved+x}" ] || continue
|
||||
export "$name=${!saved}"
|
||||
unset "$saved"
|
||||
done
|
||||
return 0
|
||||
fi
|
||||
[ "${BL_DESKTOP:-}" = 1 ] && [ "${verb:-}" = waitforexitandrun ] && [ -x "$gpu" ] || return 0
|
||||
local choice=${BL_DESKTOP_GPU:-on}
|
||||
case "${choice,,}" in off | 0 | no | false) return 0 ;; esac
|
||||
case " $* " in *iscriptevaluator*) return 0 ;; esac
|
||||
local clear=()
|
||||
for name in "${names[@]}"; do
|
||||
[ -n "${!name+x}" ] || continue
|
||||
export "BL_GPU_SAVED_$name=${!name}"
|
||||
clear+=(-u "$name")
|
||||
done
|
||||
echo "droiddeck-gpu: the desktop starts this game on the GPU" >&2
|
||||
exec env "${clear[@]}" "$gpu" "$0" "$verb" "$@"
|
||||
}
|
||||
bl_desktop_gpu "$@"
|
||||
"""
|
||||
BL_COMPONENTS_SETUP = """
|
||||
bl_components() {
|
||||
base=$1
|
||||
@@ -380,7 +408,7 @@ LAUNCHER_TEMPLATE = LAUNCHER_SH
|
||||
|
||||
def launcher_sh(sources=SOURCES):
|
||||
return (LAUNCHER_TEMPLATE % " ".join('"%s"' % n for n in sources)).replace(
|
||||
"verb=$1; shift", "verb=$1; shift\n" + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
"verb=$1; shift", "verb=$1; shift\n" + BL_DESKTOP_GPU_SETUP + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
+ BL_VACDIAG_SETUP + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
|
||||
|
||||
|
||||
@@ -469,7 +497,7 @@ verb=$1; shift
|
||||
case $verb in
|
||||
getcompatpath | getnativepath) printf '%s\\n' "$1"; exit 0 ;;
|
||||
esac
|
||||
""" + BL_GAME_CPUS_SETUP + """
|
||||
""" + BL_DESKTOP_GPU_SETUP + BL_GAME_CPUS_SETUP + """
|
||||
bl_game_cpus
|
||||
if [ -x /usr/local/bin/droiddeck-steamvr-flat ] && /usr/local/bin/droiddeck-steamvr-flat "$verb"; then
|
||||
exec /usr/local/bin/droiddeck-steamvr-game ${BL_TASKSET:-} /usr/local/bin/droiddeck-fex steam "$verb" "$@"
|
||||
@@ -652,7 +680,7 @@ def adopt_extras(tools):
|
||||
try:
|
||||
body = (EXTRA_WRAPPER_SH % entry_point).replace(
|
||||
'here=$(dirname "$0")',
|
||||
'here=$(dirname "$0")\n' + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
'here=$(dirname "$0")\n' + BL_DESKTOP_GPU_SETUP + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
+ BL_VACDIAG_SETUP + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
|
||||
write_changed(wrapper, body, 0o755)
|
||||
write_changed(manifest, EXTRA_MANIFEST_VDF)
|
||||
|
||||
Reference in new issue
Block a user