mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 22:36:00 +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
@@ -947,6 +947,33 @@ class LaunchTest(Harness):
|
||||
os.environ["SteamGameId"] = "0"
|
||||
self.assertEqual(BNET["proton_options"](), [])
|
||||
|
||||
def test_on_the_desktop_battle_net_restarts_on_the_gpu_unless_turned_off(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
gpu = os.path.join(tmp, "droiddeck-gpu")
|
||||
with open(gpu, "w") as out:
|
||||
out.write("#!/bin/sh\n")
|
||||
os.chmod(gpu, 0o755)
|
||||
with mock.patch.dict(BNET, {"BIN": tmp}), mock.patch.dict(os.environ, {"BL_DESKTOP": "1"}):
|
||||
os.environ.pop("BL_DESKTOP_GPU", None)
|
||||
os.environ.pop("BL_DESKTOP_GPU_CHILD", None)
|
||||
self.assertEqual(BNET["desktop_gpu"](), gpu)
|
||||
for choice in ("off", "0", "No", "false"):
|
||||
os.environ["BL_DESKTOP_GPU"] = choice
|
||||
self.assertIsNone(BNET["desktop_gpu"]())
|
||||
os.environ["BL_DESKTOP_GPU"] = "on"
|
||||
os.environ["BL_DESKTOP_GPU_CHILD"] = "1"
|
||||
self.assertIsNone(BNET["desktop_gpu"]())
|
||||
os.environ.pop("BL_DESKTOP_GPU_CHILD")
|
||||
os.environ["BL_DESKTOP"] = "0"
|
||||
self.assertIsNone(BNET["desktop_gpu"]())
|
||||
os.environ["BL_DESKTOP"] = "1"
|
||||
os.chmod(gpu, 0o644)
|
||||
self.assertIsNone(BNET["desktop_gpu"]())
|
||||
|
||||
def test_on_the_gpu_battle_net_fills_the_screen_instead_of_a_window(self):
|
||||
with mock.patch.dict(os.environ, {"BL_DESKTOP": "1", "BL_DESKTOP_GPU_CHILD": "1", "BL_WIDTH": "1280", "BL_HEIGHT": "720", "SteamGameId": "0"}):
|
||||
self.assertEqual(BNET["proton_options"](), ["--desktop", "1280x720"])
|
||||
|
||||
def test_under_gamescope_battle_net_gets_a_desktop_of_the_screens_size(self):
|
||||
with mock.patch.dict(os.environ, {"BL_WIDTH": "1280", "BL_HEIGHT": "720", "SteamGameId": "0"}):
|
||||
os.environ.pop("BL_DESKTOP", None)
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
TOOLS = Path(__file__).resolve().parents[1]
|
||||
GPU = TOOLS / "linuxfs/desktop/droiddeck-gpu"
|
||||
WINDOW = TOOLS / "linuxfs/overlay/usr/local/bin/droiddeck-gpu-window"
|
||||
KEYS = ("MESA_VK_WSI_DEBUG", "SDL_VIDEODRIVER", "WAYLAND_DISPLAY", "BL_GPU_CHILD_WSI", "BL_DESKTOP_GPU_CHILD")
|
||||
|
||||
|
||||
class DesktopGpuWindowTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = Path(tempfile.mkdtemp())
|
||||
self.addCleanup(shutil.rmtree, self.tmp, True)
|
||||
self.out = self.tmp / "gamescope.json"
|
||||
fake = self.tmp / "gamescope"
|
||||
fake.write_text("#!%s\nimport json, os, sys\njson.dump({'args': sys.argv[1:], 'env': {k: os.environ.get(k) for k in %r}}, open(%r, 'w'))\n"
|
||||
% (sys.executable, KEYS, str(self.out)))
|
||||
fake.chmod(0o755)
|
||||
|
||||
def run_gpu(self, **env):
|
||||
base = {k: v for k, v in os.environ.items() if k not in KEYS + ("BL_DEBUG_DIR", "BL_DESKTOP_GPU_WINDOW")}
|
||||
base.update(PATH="%s:%s" % (self.tmp, os.environ["PATH"]), BL_WIDTH="1280", BL_HEIGHT="720", **env)
|
||||
subprocess.run(["bash", str(GPU), "game.exe"], env=base, check=True, capture_output=True)
|
||||
return json.loads(self.out.read_text())
|
||||
|
||||
def test_on_the_desktop_the_game_gets_a_window_of_its_own(self):
|
||||
run = self.run_gpu(WAYLAND_DISPLAY="wayland-1", MESA_VK_WSI_DEBUG="sw,linear")
|
||||
self.assertEqual(run["args"][:2], ["--backend", "sdl"])
|
||||
self.assertNotIn("-f", run["args"])
|
||||
self.assertEqual(run["args"][-2:], ["/usr/local/bin/droiddeck-gpu-window", "game.exe"])
|
||||
self.assertEqual(run["env"]["WAYLAND_DISPLAY"], "wayland-1")
|
||||
self.assertEqual(run["env"]["SDL_VIDEODRIVER"], "wayland")
|
||||
self.assertEqual(run["env"]["MESA_VK_WSI_DEBUG"], "sw")
|
||||
self.assertEqual(run["env"]["BL_GPU_CHILD_WSI"], "linear")
|
||||
self.assertEqual(run["env"]["BL_DESKTOP_GPU_CHILD"], "1")
|
||||
|
||||
def test_full_screen_stays_available(self):
|
||||
for env in ({"WAYLAND_DISPLAY": "wayland-1", "BL_DESKTOP_GPU_WINDOW": "0"}, {"WAYLAND_DISPLAY": "wayland-0"}, {}):
|
||||
run = self.run_gpu(**env)
|
||||
self.assertEqual(run["args"][:2], ["--backend", "wayland"])
|
||||
self.assertIn("-f", run["args"])
|
||||
self.assertEqual(run["env"]["WAYLAND_DISPLAY"], "wayland-0")
|
||||
self.assertIsNone(run["env"]["MESA_VK_WSI_DEBUG"])
|
||||
self.assertIsNone(run["env"]["BL_GPU_CHILD_WSI"])
|
||||
|
||||
def test_the_game_inside_the_window_gets_its_own_settings_back(self):
|
||||
script = "import json, os; print(json.dumps({k: os.environ.get(k) for k in %r}))" % (KEYS,)
|
||||
for saved, expected in (("linear", "linear"), ("", None)):
|
||||
env = {k: v for k, v in os.environ.items() if k not in KEYS + ("DISPLAY",)}
|
||||
env.update(BL_GPU_CHILD_WSI=saved, MESA_VK_WSI_DEBUG="sw", SDL_VIDEODRIVER="wayland")
|
||||
out = subprocess.run([sys.executable, str(WINDOW), sys.executable, "-c", script], env=env,
|
||||
check=True, capture_output=True, text=True).stdout
|
||||
child = json.loads(out)
|
||||
self.assertEqual(child["MESA_VK_WSI_DEBUG"], expected)
|
||||
self.assertEqual(child["SDL_VIDEODRIVER"], "x11")
|
||||
self.assertIsNone(child["BL_GPU_CHILD_WSI"])
|
||||
|
||||
def test_outside_a_window_the_game_keeps_its_settings(self):
|
||||
script = "import os; print(os.environ.get('MESA_VK_WSI_DEBUG'), os.environ.get('SDL_VIDEODRIVER'))"
|
||||
env = {k: v for k, v in os.environ.items() if k not in KEYS + ("DISPLAY",)}
|
||||
env.update(MESA_VK_WSI_DEBUG="linear", SDL_VIDEODRIVER="x11")
|
||||
out = subprocess.run([sys.executable, str(WINDOW), sys.executable, "-c", script], env=env,
|
||||
check=True, capture_output=True, text=True).stdout.split()
|
||||
self.assertEqual(out, ["linear", "x11"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -77,6 +77,35 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
env=env, text=True, capture_output=True, check=True)
|
||||
self.assertEqual(result.stdout.strip(), expected)
|
||||
|
||||
def test_desktop_games_restart_on_the_gpu_with_steams_preloads_handed_back(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
home = Path(tmp)
|
||||
gpu = home / "gpu"
|
||||
gpu.write_text("#!/bin/bash\necho \"gpu LD_PRELOAD=${LD_PRELOAD-unset}\"\nexport BL_DESKTOP_GPU_CHILD=1\nexec \"$@\"\n")
|
||||
gpu.chmod(0o755)
|
||||
launcher = home / "launcher"
|
||||
setup = COMPAT["BL_DESKTOP_GPU_SETUP"].replace("/usr/local/bin/droiddeck-gpu", str(gpu))
|
||||
launcher.write_text("#!/bin/bash\nverb=$1; shift\n" + setup + "echo \"game $verb $* LD_PRELOAD=${LD_PRELOAD-unset} saved=${BL_GPU_SAVED_LD_PRELOAD-unset}\"\n")
|
||||
launcher.chmod(0o755)
|
||||
base = {key: value for key, value in os.environ.items() if not key.startswith("BL_")}
|
||||
base["LD_PRELOAD"] = "overlay.so"
|
||||
for extra, args, expected in (
|
||||
({"BL_DESKTOP": "1"}, ["waitforexitandrun", "game.exe"],
|
||||
["gpu LD_PRELOAD=unset", "game waitforexitandrun game.exe LD_PRELOAD=overlay.so saved=unset"]),
|
||||
({"BL_DESKTOP": "1", "BL_DESKTOP_GPU": "Off"}, ["waitforexitandrun", "game.exe"],
|
||||
["game waitforexitandrun game.exe LD_PRELOAD=overlay.so saved=unset"]),
|
||||
({"BL_DESKTOP": "1"}, ["run", "setup.exe"],
|
||||
["game run setup.exe LD_PRELOAD=overlay.so saved=unset"]),
|
||||
({"BL_DESKTOP": "1"}, ["waitforexitandrun", "iscriptevaluator.exe"],
|
||||
["game waitforexitandrun iscriptevaluator.exe LD_PRELOAD=overlay.so saved=unset"]),
|
||||
({}, ["waitforexitandrun", "game.exe"],
|
||||
["game waitforexitandrun game.exe LD_PRELOAD=overlay.so saved=unset"]),
|
||||
):
|
||||
with self.subTest(extra=extra, args=args):
|
||||
result = subprocess.run([str(launcher)] + args, env=dict(base, **extra),
|
||||
text=True, capture_output=True, check=True)
|
||||
self.assertEqual(result.stdout.splitlines(), expected)
|
||||
|
||||
def test_the_install_script_evaluator_gets_its_scripts_marked_first(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
|
||||
Reference in new issue
Block a user