diff --git a/app/src/main/java/com/droiddeck/launcher/QuestXrActivity.kt b/app/src/main/java/com/droiddeck/launcher/QuestXrActivity.kt index 126d73cbcf..e3b8bbabaf 100644 --- a/app/src/main/java/com/droiddeck/launcher/QuestXrActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/QuestXrActivity.kt @@ -17,7 +17,7 @@ class QuestXrActivity : NativeActivity() { override fun onCreate(savedInstanceState: Bundle?) { if (intent.getBooleanExtra("guest_surface", false) || intent.getBooleanExtra("guest_frames", false)) { if (intent.getBooleanExtra("guest_surface", false)) intent.putExtra("surface_test", true) - SessionService.resume(this) + SessionService.setXrActivityVisible(this, true) } super.onCreate(savedInstanceState) } @@ -79,4 +79,9 @@ class QuestXrActivity : NativeActivity() { SessionService.setXrActivityVisible(this, false) super.onDestroy() } + + override fun onStop() { + SessionService.setXrActivityVisible(this, false) + super.onStop() + } } 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 b61ac122c7..e75e54aded 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -104,6 +104,7 @@ object SessionFiles { listOf("NOTICE", "GPL-2", "GPL-3", "LGPL-2.1", "7zip-License", "7zip-unRarLicense").map { "usr/local/share/licenses/droiddeck-msitools/$it" } val vr = listOf( "droiddeck/bin/linuxarm64/driver_droiddeck.so", + "droiddeck/bin/linuxarm64/xr-display-mode", "droiddeck/driver.vrdrivermanifest", "droiddeck/resources/settings/default.vrsettings", "layer/libVkLayer_droiddeck_vr.so", diff --git a/docs/development/quest-openxr.md b/docs/development/quest-openxr.md index 88c142328f..d1f1808424 100644 --- a/docs/development/quest-openxr.md +++ b/docs/development/quest-openxr.md @@ -269,7 +269,33 @@ The 2D panel's onStop could also suspend the guest after the XR surface became visible. XR visibility now has a separate service lease; panel transitions cannot overwrite it, and normal suspend rules return when XR visibility is lost. Focused visibility/background-policy tests pass. A signed full-app build -and live validation of this lifecycle fix are pending. +and live validation of this lifecycle fix are pending. The lease is acquired +before native initialization so removing the old panel task cannot end the +guest during the handoff, and it is explicitly released on stop/destruction. + +SteamVR's virtual display still advertised 1920x1080 at 60 Hz while the XR +driver advertised 3360x1760 at 120 Hz. The compositor could not find a matching +surface and crashed after its first submission. A controlled runtime override +to the XR geometry restores the headless display surface and sustained 120 Hz +submission: over 10,000 Present calls were observed. Owned images remain at +zero because the producer-fence check correctly refuses them. + +The helper now obtains display geometry from fresh, validated tracking using a +small ARM64 reader built against the same IPC headers. Explicit user overrides +remain unchanged and older/stale sessions retain the normal fallback. Host +tracking tests and four shell-helper regressions pass. The actual Quest reader +prints 3360x1760@120, and automatic selection reproduces sustained submission. +Startup stdout is now retained in Steam's guest log directory, with the old +runtime-log path preserved as a symlink; a session restart no longer loses it. + +A minimal native Vulkan probe on the real Quest reports export/import support +for SYNC_FD fences/semaphores, but not OPAQUE_FD handles. This distinguishes the +unsupported implicit DMA-buf fence export from available explicit Vulkan GPU +completion primitives. Implementing the explicit producer synchronization is +still necessary; the existing shared-semaphore wait-dropping workaround must +not be treated as correct synchronization. The desktop's dashboard helper also +lacks X display authorization; no authentication or permission check was +bypassed to work around that error. ## Remaining stages diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steamvr b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steamvr index b11e88c875..abc369a828 100644 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-steamvr +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-steamvr @@ -78,6 +78,10 @@ JSON if [ -S /run/droiddeck/droiddeck-xr-frames ] && [ -z "${DROIDDECK_VR_PRESENT:-}" ]; then export DROIDDECK_VR_PRESENT=questframes fi + if [ -z "${DROIDDECK_VR_DISPLAY_MODE:-}" ] && [ -x "$driver/bin/linuxarm64/xr-display-mode" ]; then + mode=$("$driver/bin/linuxarm64/xr-display-mode") || mode= + if [ -n "$mode" ]; then export DROIDDECK_VR_DISPLAY_MODE="$mode"; fi + fi shims=$state/shims mkdir -p "$shims" @@ -89,7 +93,9 @@ JSON : > "$state/active" cd "$steamvr/bin/linuxarm64" || exit 1 - setsid ./vrstartup > "$state/vrstartup.log" 2>&1 < /dev/null & + startup_log=$logs/droiddeck-vrstartup.log + ln -sf "$startup_log" "$state/vrstartup.log" + setsid ./vrstartup > "$startup_log" 2>&1 < /dev/null & echo "SteamVR starting; logs in $logs and $state/vrstartup.log" ;; *) diff --git a/tools/tests/test_steamvr_helper.py b/tools/tests/test_steamvr_helper.py new file mode 100644 index 0000000000..87d343a6fd --- /dev/null +++ b/tools/tests/test_steamvr_helper.py @@ -0,0 +1,79 @@ +import os +import shutil +import subprocess +import tempfile +import time +import unittest +from pathlib import Path + + +SOURCE = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-steamvr' + + +class SteamVrHelperTest(unittest.TestCase): + def setUp(self): + self.temporary = tempfile.TemporaryDirectory() + self.addCleanup(self.temporary.cleanup) + self.root = Path(self.temporary.name) + self.home = self.root / 'home' + self.runtime = self.root / 'runtime' + self.commands = self.root / 'commands' + self.driver = self.root / 'driver/droiddeck/bin/linuxarm64' + self.steamvr = self.root / 'steamvr' + for directory in (self.commands, self.driver, self.steamvr / 'bin/linuxarm64'): + directory.mkdir(parents=True) + self.helper = self.root / 'droiddeck-steamvr' + self.helper.write_text(SOURCE.read_text(), encoding='utf-8') + self.executable(self.commands / 'pgrep', 'exit 1') + self.executable(self.commands / 'sleep', 'exit 0') + self.executable(self.commands / 'xset', 'exit 0') + self.executable(self.commands / 'setsid', 'exec "$@"') + self.executable(self.driver / 'xr-display-mode', 'echo 3360x1760@120') + self.executable(self.steamvr / 'bin/linuxarm64/vrstartup', + 'echo "display=${DROIDDECK_VR_DISPLAY_MODE:-unset}"') + (self.driver / 'driver_droiddeck.so').touch() + self.environment = dict(os.environ) + self.environment.pop('DROIDDECK_VR_DISPLAY_MODE', None) + self.environment.pop('DROIDDECK_VR_PRESENT', None) + self.environment.update(HOME=str(self.home), XDG_RUNTIME_DIR=str(self.runtime), + STEAMVR=str(self.steamvr), DROIDDECK_VR_DIR=str(self.root / 'driver'), + PATH=str(self.commands) + os.pathsep + os.environ['PATH']) + + def executable(self, destination, body): + destination.write_text('#!/bin/sh\n' + body + '\n', encoding='utf-8') + destination.chmod(0o755) + + def start(self): + result = subprocess.run(['sh', str(self.helper), 'start'], env=self.environment, + capture_output=True, text=True, timeout=5) + self.assertEqual(result.returncode, 0, result.stderr) + log = self.home / '.local/share/Steam/logs/droiddeck-vrstartup.log' + deadline = time.monotonic() + 2 + while time.monotonic() < deadline: + if log.is_file() and 'display=' in log.read_text(): + return log + time.sleep(0.01) + self.fail('Startup log did not arrive') + + def test_fresh_runtime_mode_is_selected_and_log_survives_runtime_cleanup(self): + log = self.start() + self.assertEqual(log.read_text().strip(), 'display=3360x1760@120') + self.assertEqual((self.runtime / 'droiddeck-steamvr/vrstartup.log').resolve(), log) + shutil.rmtree(self.runtime) + self.assertTrue(log.is_file()) + + def test_explicit_display_override_is_preserved(self): + self.environment['DROIDDECK_VR_DISPLAY_MODE'] = '1920x1080@90' + self.assertEqual(self.start().read_text().strip(), 'display=1920x1080@90') + + def test_stale_or_missing_tracking_keeps_the_default(self): + self.executable(self.driver / 'xr-display-mode', 'exit 1') + self.assertEqual(self.start().read_text().strip(), 'display=unset') + + def test_older_runtime_without_the_reader_still_starts(self): + (self.driver / 'xr-display-mode').unlink() + self.assertEqual(self.start().read_text().strip(), 'display=unset') + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/vr/build.sh b/tools/vr/build.sh index fc90d89058..037613b74f 100755 --- a/tools/vr/build.sh +++ b/tools/vr/build.sh @@ -29,6 +29,8 @@ compile() { local cmd=(sh -c ' set -e mkdir -p build/vr/stub + aarch64-linux-gnu-g++ -std=c++17 -O2 -Wall -Wextra -Werror -static-libstdc++ -static-libgcc -pthread \ + -o build/vr/out/droiddeck/bin/linuxarm64/xr-display-mode tools/vr/src/xr_display_mode.cpp aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wl,-soname,libwayland-client.so.0 -Itools/vr/third_party/wayland \ -o build/vr/stub/libwayland-client.so tools/vr/src/wayland_client_stub.c aarch64-linux-gnu-gcc -c -fPIC -O2 -Itools/vr/third_party/wayland -o build/vr/xdg-shell-protocol.o \ diff --git a/tools/vr/src/xr_display_mode.cpp b/tools/vr/src/xr_display_mode.cpp new file mode 100644 index 0000000000..f37aca258f --- /dev/null +++ b/tools/vr/src/xr_display_mode.cpp @@ -0,0 +1,11 @@ +#include "xr_display_mode.h" +#include + +int main(int argc, char **argv) { + XrTrackingFile reader(argc > 1 ? argv[1] : "/run/droiddeck/" DROIDDECK_XR_FILE); + DroidDeckXrTracking tracking{}; + if (!reader.Read(&tracking)) return 1; + auto mode = XrDisplayMode(tracking); + if (mode.empty()) return 1; + std::puts(mode.c_str()); +} diff --git a/tools/vr/src/xr_display_mode.h b/tools/vr/src/xr_display_mode.h new file mode 100644 index 0000000000..c8dba6c25e --- /dev/null +++ b/tools/vr/src/xr_display_mode.h @@ -0,0 +1,9 @@ +#pragma once +#include "xr_tracking_file.h" + +inline std::string XrDisplayMode(const DroidDeckXrTracking &tracking) { + if (!XrTrackingFile::Fresh(tracking)) return {}; + auto refresh = static_cast(std::llround(1000000000.0 / tracking.period_ns)); + return std::to_string(tracking.eyes[0].width * 2) + "x" + std::to_string(tracking.eyes[0].height) + + "@" + std::to_string(refresh); +} diff --git a/tools/vr/tests/test_xr_tracking.cpp b/tools/vr/tests/test_xr_tracking.cpp index e9fe5251c4..527240260d 100644 --- a/tools/vr/tests/test_xr_tracking.cpp +++ b/tools/vr/tests/test_xr_tracking.cpp @@ -1,4 +1,5 @@ #include "../src/xr_tracking_file.h" +#include "../src/xr_display_mode.h" #include #include #include @@ -23,6 +24,18 @@ int main(int argc, char **argv) { assert(reader.Read(&packet)); assert(XrTrackingFile::Fresh(packet)); assert(packet.head.position[1] == 1.6f); assert(XrTrackingFile::Tracked(packet.head)); + assert(XrDisplayMode(packet) == "3360x1760@72"); + auto displayTracking = packet; + displayTracking.period_ns = 11111111; + assert(XrDisplayMode(displayTracking) == "3360x1760@90"); + displayTracking.period_ns = 8333547; + assert(XrDisplayMode(displayTracking) == "3360x1760@120"); + displayTracking.active = 0; + assert(XrDisplayMode(displayTracking).empty()); + displayTracking = packet; displayTracking.sampled_ns -= 1000000000LL; + assert(XrDisplayMode(displayTracking).empty()); + displayTracking = packet; displayTracking.period_ns = 0; + assert(XrDisplayMode(displayTracking).empty()); auto invalidPose = packet.head; invalidPose.flags = 7; assert(!XrTrackingFile::Tracked(invalidPose)); invalidPose = packet.head; invalidPose.orientation[3] = 0;