From 57f954025ebb263fc90e658d2847cb19a69a8983 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Wed, 7 Feb 2024 16:49:57 +0100 Subject: [PATCH] openxr: submit dummy layer if nothing is visible --- src/backend/openxr/lines.rs | 9 +++++++++ src/backend/openxr/mod.rs | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/backend/openxr/lines.rs b/src/backend/openxr/lines.rs index eac21e7..8d5c1b6 100644 --- a/src/backend/openxr/lines.rs +++ b/src/backend/openxr/lines.rs @@ -7,6 +7,7 @@ use std::{ atomic::{AtomicUsize, Ordering}, Arc, }, + usize, }; use vulkano::{command_buffer::CommandBufferUsage, format::Format, image::view::ImageView}; @@ -152,6 +153,14 @@ impl LinePool { quads } + + /// the number of lines that are waiting to be drawn + pub(super) fn num_pending(&self) -> usize { + self.lines + .values() + .filter(|l| l.maybe_line.is_some()) + .count() + } } pub(super) struct Line { diff --git a/src/backend/openxr/mod.rs b/src/backend/openxr/mod.rs index 6867a32..99b4ed1 100644 --- a/src/backend/openxr/mod.rs +++ b/src/backend/openxr/mod.rs @@ -7,6 +7,7 @@ use std::{ time::Duration, }; +use glam::Affine3A; use openxr as xr; use vulkano::{command_buffer::CommandBufferUsage, Handle, VulkanObject}; @@ -280,6 +281,17 @@ pub fn openxr_run(running: Arc) -> Result<(), BackendError> { }; } + if layers.is_empty() && lines.num_pending() == 0 { + // HACK: we need to submit at least 1 layer, else the session hangs + lines.draw_from( + pointer_lines[0], + Affine3A::IDENTITY, + 0.002, + 0, + &app_state.input_state.hmd, + ); + } + for quad in lines.present_xr(&xr_state, &mut command_buffer) { layers.push((0.0, quad)); }