mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
fix(desktop): Flatpak and Snap apps get the game GPU setting (#2295)
The session's TU_DEBUG=sysmem is meant for the Steam client and Chromium-based apps. Flatpak and Snap apps inherited it, so emulators and other programs installed that way rendered through system memory. droiddeck-game-env now holds the Chromium check next to game_gpu, and a small droiddeck-game-gpu wrapper applies both to any program. The AppImage, Flatpak and Snap launchers use it, so the rule lives in one place.
This commit is contained in:
1 parent
3bb279f635
commit
1760f008ae
9 files changed
+221
-11
No files matched your search
@@ -25,12 +25,6 @@ if [ -n "$(find -H "$APPDIR" -maxdepth 4 \( -name chrome-sandbox -o -name chrome
|
||||
flags+=(--ozone-platform=x11)
|
||||
fi
|
||||
fi
|
||||
if [ -n "${DROIDDECK_GAME_TU_DEBUG+set}" ]; then
|
||||
if [ ${#flags[@]} -eq 0 ]; then
|
||||
if [ -n "$DROIDDECK_GAME_TU_DEBUG" ]; then export TU_DEBUG=$DROIDDECK_GAME_TU_DEBUG; else unset TU_DEBUG; fi
|
||||
fi
|
||||
unset DROIDDECK_GAME_TU_DEBUG
|
||||
fi
|
||||
qt=$(cat "$dir/qt" 2>/dev/null)
|
||||
case $qt in wayland|xcb) ;; *) qt=auto ;; esac
|
||||
wayland=${GAMESCOPE_WAYLAND_DISPLAY:-${WAYLAND_DISPLAY:-}}
|
||||
@@ -61,6 +55,9 @@ if [ -x /usr/local/bin/droiddeck-fex ]; then
|
||||
*) run=(/usr/local/bin/droiddeck-fex run --mode "$fex" --for "$APPDIR" -- "$APPDIR/AppRun") ;;
|
||||
esac
|
||||
fi
|
||||
gpu=("${BASH_SOURCE[0]%/*}/droiddeck-game-gpu")
|
||||
[ ${#flags[@]} -gt 0 ] && gpu+=(--chromium)
|
||||
run=("${gpu[@]}" -- "${run[@]}")
|
||||
echo "== appimage $ARGV0 ($APPDIR) ${flags[*]} FEX $fex Qt $qt${QT_QPA_PLATFORM:+ ($QT_QPA_PLATFORM)}"
|
||||
cd "$APPDIR" || exit 1
|
||||
started=$(mktemp "${TMPDIR:-/tmp}/droiddeck-appimage.XXXXXX")
|
||||
|
||||
@@ -11,8 +11,16 @@ if [ -n "${BL_INSIDE:-}" ] || [ -n "${GAMESCOPE_WAYLAND_DISPLAY:-}" ]; then
|
||||
export XDG_SESSION_TYPE=x11
|
||||
socket=(--nosocket=wayland --socket=x11)
|
||||
fi
|
||||
app=
|
||||
for arg in "$@"; do
|
||||
case $arg in -*) ;; *) app=$arg; break ;; esac
|
||||
done
|
||||
gpu=("${BASH_SOURCE[0]%/*}/droiddeck-game-gpu")
|
||||
location=
|
||||
[ -n "$app" ] && location=$(flatpak info --show-location "$app" 2>/dev/null)
|
||||
[ -n "$location" ] && gpu+=(--for "$location/files")
|
||||
echo "== flatpak run ${socket[*]} $*"
|
||||
if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ] && command -v dbus-run-session >/dev/null 2>&1; then
|
||||
exec dbus-run-session -- flatpak run "${socket[@]}" "$@"
|
||||
exec "${gpu[@]}" -- dbus-run-session -- flatpak run "${socket[@]}" "$@"
|
||||
fi
|
||||
exec flatpak run "${socket[@]}" "$@"
|
||||
exec "${gpu[@]}" -- flatpak run "${socket[@]}" "$@"
|
||||
@@ -11,6 +11,7 @@ import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
GAME_TU_DEBUG = "DROIDDECK_GAME_TU_DEBUG"
|
||||
CHROMIUM_FILES = {"chrome-sandbox", "chrome_100_percent.pak", "v8_context_snapshot.bin"}
|
||||
SYNC_KEYS = ("BL_SYNC", "BL_SYNC_FALLBACK", "BL_FSYNC_FIRST", "BL_SYNC_MIN_NOFILE", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC", "PROTON_NO_NTSYNC", "WINEESYNC")
|
||||
SEED_REDISTS = "/usr/local/bin/droiddeck-seed-redists"
|
||||
PACK_KEYS = ("WINESERVER", "BL_SYNC_PACK", "WINEESYNC", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC")
|
||||
@@ -346,11 +347,23 @@ def win_components(compat, app_id):
|
||||
return ""
|
||||
|
||||
|
||||
def game_gpu(env):
|
||||
def chromium_app(folder):
|
||||
root = os.path.realpath(folder)
|
||||
for top, dirs, files in os.walk(root):
|
||||
if CHROMIUM_FILES.intersection(files) or CHROMIUM_FILES.intersection(dirs):
|
||||
return True
|
||||
if os.path.relpath(top, root).count(os.sep) >= 2:
|
||||
dirs[:] = []
|
||||
return False
|
||||
|
||||
|
||||
def game_gpu(env, keep=False):
|
||||
if GAME_TU_DEBUG not in env:
|
||||
return env
|
||||
result = env.copy()
|
||||
value = result.pop(GAME_TU_DEBUG)
|
||||
if keep:
|
||||
return result
|
||||
if value:
|
||||
result["TU_DEBUG"] = value
|
||||
else:
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
import runpy
|
||||
import sys
|
||||
|
||||
BIN_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def main(argv):
|
||||
keep = False
|
||||
folder = None
|
||||
while argv and argv[0] != "--":
|
||||
if argv[0] == "--chromium":
|
||||
keep = True
|
||||
argv = argv[1:]
|
||||
elif argv[0] == "--for" and len(argv) > 1:
|
||||
folder = argv[1]
|
||||
argv = argv[2:]
|
||||
else:
|
||||
break
|
||||
if argv and argv[0] == "--":
|
||||
argv = argv[1:]
|
||||
if not argv:
|
||||
print("usage: droiddeck-game-gpu [--chromium] [--for FOLDER] -- PROGRAM [ARGS...]", file=sys.stderr)
|
||||
return 2
|
||||
env = dict(os.environ)
|
||||
try:
|
||||
game_env = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-game-env"))
|
||||
if folder and not keep:
|
||||
keep = game_env["chromium_app"](folder)
|
||||
env = game_env["game_gpu"](env, keep)
|
||||
except Exception as error:
|
||||
print("droiddeck-game-gpu: the game GPU setting was not applied (%s)" % error, file=sys.stderr)
|
||||
try:
|
||||
os.execvpe(argv[0], argv, env)
|
||||
except OSError as error:
|
||||
print("droiddeck-game-gpu: %s: %s" % (argv[0], error.strerror), file=sys.stderr)
|
||||
return 127
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -1,11 +1,13 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
import re
|
||||
import runpy
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
import yaml
|
||||
|
||||
BIN_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
SNAP_DIR = "/snap"
|
||||
HOST_DIRS = ("/etc", "/home", "/root", "/tmp", "/run", "/var/snap", "/var/lib/snapd", "/var/tmp", "/var/log",
|
||||
"/media", "/mnt", "/snap", "/usr/src", "/lib/modules")
|
||||
@@ -59,6 +61,15 @@ def content_binds(name, meta, env):
|
||||
return out
|
||||
|
||||
|
||||
def game_gpu(env, snap):
|
||||
try:
|
||||
game_env = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-game-env"))
|
||||
return game_env["game_gpu"](env, game_env["chromium_app"](snap))
|
||||
except Exception as error:
|
||||
print(f"droiddeck-snap-run: the game GPU setting was not applied ({error})", file=sys.stderr)
|
||||
return env
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) < 3:
|
||||
print("usage: droiddeck-snap-run SNAP APP [ARG...]", file=sys.stderr)
|
||||
@@ -72,7 +83,7 @@ def main(argv):
|
||||
revision = os.path.basename(os.path.realpath(f"{SNAP_DIR}/{name}/current"))
|
||||
home = os.environ.get("HOME", "/root")
|
||||
snap = f"{SNAP_DIR}/{name}/{revision}"
|
||||
env = dict(os.environ)
|
||||
env = game_gpu(dict(os.environ), snap)
|
||||
for k in ("LD_PRELOAD", "LD_LIBRARY_PATH"):
|
||||
env.pop(k, None)
|
||||
env.update({
|
||||
|
||||
Reference in new issue
Block a user