diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index e75e54aded..972988ead3 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -71,6 +71,7 @@ object SessionFiles { "usr/local/bin/droiddeck-steam-games" to "usr/local/bin/droiddeck-steam-games", "usr/local/bin/droiddeck-pad-defaults" to "usr/local/bin/droiddeck-pad-defaults", "usr/local/bin/droiddeck-steamvr" to "usr/local/bin/droiddeck-steamvr", + "usr/local/bin/droiddeck-steamvr-game" to "usr/local/bin/droiddeck-steamvr-game", "usr/local/bin/droiddeck-bwrap" to "usr/local/bin/droiddeck-bwrap", "usr/local/bin/droiddeck-flatpak" to "usr/local/bin/droiddeck-flatpak", "usr/local/bin/droiddeck-flatpak-setup" to "usr/local/bin/droiddeck-flatpak-setup", diff --git a/docs/quest.md b/docs/quest.md index ae924b0370..968618ff6b 100644 --- a/docs/quest.md +++ b/docs/quest.md @@ -91,3 +91,19 @@ controller models and trigger animation. That run delivered about 8.5 new stereo images per second despite a 90 Hz XR session. This branch retains the safe owned-frame transfer path; reducing transfer cost, validating game input and testing actual VR games remain necessary. + +### Experimental flat games in SteamVR + +Start SteamVR first, then add `droiddeck-steamvr-game %command%` to a flat +game's Steam launch options. Remove that prefix to restore normal panel launch. +This runs a nested, unmodified Gamescope OpenVR backend for that game. Gamescope +owns the GPU overlay, placement and input routing; no CPU screen capture or +PipeWire service is used. The existing DroidDeck Vulkan synchronization layer +remains enabled. On Quest, a connected XR receiver selects Gamescope's Vulkan +texture sharing instead of DMA-BUF modifiers. Explicit environment overrides +are preserved; other devices retain the upstream modifier default. + +An upstream GPU cube overlay has been observed on Quest 3. Flat-game stability, +controller interaction and performance still require hardware validation. This +uses Valve's public Gamescope backend; the exact Steam Frame OS launch setup +has not been verified. diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steamvr-game b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steamvr-game new file mode 100755 index 0000000000..4fba6e5b57 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steamvr-game @@ -0,0 +1,21 @@ +#!/bin/sh +set -eu + +[ "$#" -gt 0 ] || { echo 'usage: droiddeck-steamvr-game COMMAND [ARG...]' >&2; exit 2; } +pgrep -x vrserver >/dev/null 2>&1 || { + echo 'Start SteamVR before launching a game with droiddeck-steamvr-game.' >&2 + exit 1 +} +vrdir=${DROIDDECK_VR_DIR:-/usr/local/lib/droiddeck-vr} +export VK_LAYER_PATH="$vrdir/layer${VK_LAYER_PATH:+:$VK_LAYER_PATH}" +export VK_INSTANCE_LAYERS="VK_LAYER_DROIDDECK_vr${VK_INSTANCE_LAYERS:+:$VK_INSTANCE_LAYERS}" +export VK_LOADER_LAYERS_DISABLE="${VK_LOADER_LAYERS_DISABLE:-~implicit~}" +# Quest's guest GPU images use Vulkan sharing rather than DMA-BUF modifiers. +if [ -S "${XDG_RUNTIME_DIR:-/run/droiddeck}/droiddeck-xr-frames" ]; then + export gamescope_vr_use_modifiers=${gamescope_vr_use_modifiers:-false} +fi +export gamescope_vr_nudge_to_visible=${gamescope_vr_nudge_to_visible:-true} +exec gamescope --backend openvr \ + --vr-overlay-key "gamescope.droiddeck.game.$$" \ + --vr-overlay-default-name 'DroidDeck game' \ + --vr-overlay-show-immediately --vr-overlay-physical-width 2.4 -- "$@" diff --git a/tools/tests/test_steamvr_game.py b/tools/tests/test_steamvr_game.py new file mode 100644 index 0000000000..2280aceaa8 --- /dev/null +++ b/tools/tests/test_steamvr_game.py @@ -0,0 +1,63 @@ +import json +import os +from pathlib import Path +import socket +import subprocess +import tempfile +import unittest + + +SOURCE = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-steamvr-game' + + +class SteamVrGameTest(unittest.TestCase): + def setUp(self): + temporary = tempfile.TemporaryDirectory() + self.addCleanup(temporary.cleanup) + self.root = Path(temporary.name) + self.helper = self.root / 'helper' + self.helper.write_text(SOURCE.read_text(), encoding='utf-8') + self.command('pgrep', '#!/bin/sh\nexit 0\n') + self.command('gamescope', '#!/usr/bin/env python3\nimport json, os, sys\n' + 'print(json.dumps(dict(argv=sys.argv[1:], modifiers=os.getenv("gamescope_vr_use_modifiers"), ' + 'layers=os.getenv("VK_INSTANCE_LAYERS"))))\n') + self.env = {key: value for key, value in os.environ.items() + if not key.startswith(('gamescope_vr_', 'VK_'))} + self.env.update(PATH=str(self.root) + os.pathsep + os.environ['PATH'], + XDG_RUNTIME_DIR=str(self.root)) + + def command(self, name, text): + path = self.root / name + path.write_text(text, encoding='utf-8') + path.chmod(0o755) + + def run_game(self, *args): + return subprocess.run(['sh', str(self.helper), *args], env=self.env, + capture_output=True, text=True, timeout=5) + + def test_native_backend_preserves_command_arguments_and_nonquest_defaults(self): + result = self.run_game('game with spaces', 'a b', '$literal') + self.assertEqual(result.returncode, 0, result.stderr) + data = json.loads(result.stdout) + self.assertEqual(data['argv'][:2], ['--backend', 'openvr']) + self.assertEqual(data['argv'][-4:], ['--', 'game with spaces', 'a b', '$literal']) + self.assertIsNone(data['modifiers']) + self.assertEqual(data['layers'], 'VK_LAYER_DROIDDECK_vr') + + def test_quest_selects_vulkan_sharing_and_preserves_explicit_override(self): + with socket.socket(socket.AF_UNIX) as receiver: + receiver.bind(str(self.root / 'droiddeck-xr-frames')) + self.assertEqual(json.loads(self.run_game('game').stdout)['modifiers'], 'false') + self.env['gamescope_vr_use_modifiers'] = 'true' + self.assertEqual(json.loads(self.run_game('game').stdout)['modifiers'], 'true') + + def test_missing_runtime_and_missing_command_fail_clearly(self): + self.assertEqual(self.run_game().returncode, 2) + self.command('pgrep', '#!/bin/sh\nexit 1\n') + result = self.run_game('game') + self.assertEqual(result.returncode, 1) + self.assertIn('Start SteamVR', result.stderr) + + +if __name__ == '__main__': + unittest.main()