openxr: overlay session
This commit is contained in:
@@ -10,6 +10,7 @@ use anyhow::{bail, ensure};
|
|||||||
use glam::{Affine3A, Quat, Vec3};
|
use glam::{Affine3A, Quat, Vec3};
|
||||||
use openxr as xr;
|
use openxr as xr;
|
||||||
use vulkano::{command_buffer::CommandBufferUsage, Handle, VulkanObject};
|
use vulkano::{command_buffer::CommandBufferUsage, Handle, VulkanObject};
|
||||||
|
use xr::OverlaySessionCreateFlagsEXTX;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::{
|
backend::{
|
||||||
@@ -64,8 +65,8 @@ pub fn openxr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
|
|||||||
app_state.hid_provider.set_desktop_extent(overlays.extent);
|
app_state.hid_provider.set_desktop_extent(overlays.extent);
|
||||||
|
|
||||||
let (session, mut frame_wait, mut frame_stream) = unsafe {
|
let (session, mut frame_wait, mut frame_stream) = unsafe {
|
||||||
xr_instance
|
let raw_session = create_overlay_session(
|
||||||
.create_session::<xr::Vulkan>(
|
&xr_instance,
|
||||||
system,
|
system,
|
||||||
&xr::vulkan::SessionCreateInfo {
|
&xr::vulkan::SessionCreateInfo {
|
||||||
instance: app_state.graphics.instance.handle().as_raw() as _,
|
instance: app_state.graphics.instance.handle().as_raw() as _,
|
||||||
@@ -80,7 +81,8 @@ pub fn openxr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
|
|||||||
queue_index: 0,
|
queue_index: 0,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap();
|
||||||
|
xr::Session::from_raw(xr_instance.clone(), raw_session, Box::new(()))
|
||||||
};
|
};
|
||||||
|
|
||||||
let stage = session
|
let stage = session
|
||||||
@@ -338,6 +340,40 @@ fn init_xr() -> Result<(xr::Instance, xr::SystemId), anyhow::Error> {
|
|||||||
|
|
||||||
Ok((xr_instance, system))
|
Ok((xr_instance, system))
|
||||||
}
|
}
|
||||||
|
unsafe fn create_overlay_session(
|
||||||
|
instance: &xr::Instance,
|
||||||
|
system: xr::SystemId,
|
||||||
|
info: &xr::vulkan::SessionCreateInfo,
|
||||||
|
) -> Result<xr::sys::Session, xr::sys::Result> {
|
||||||
|
let overlay = xr::sys::SessionCreateInfoOverlayEXTX {
|
||||||
|
ty: xr::sys::SessionCreateInfoOverlayEXTX::TYPE,
|
||||||
|
next: std::ptr::null(),
|
||||||
|
create_flags: OverlaySessionCreateFlagsEXTX::EMPTY,
|
||||||
|
session_layers_placement: 5,
|
||||||
|
};
|
||||||
|
let binding = xr::sys::GraphicsBindingVulkanKHR {
|
||||||
|
ty: xr::sys::GraphicsBindingVulkanKHR::TYPE,
|
||||||
|
next: &overlay as *const _ as *const _,
|
||||||
|
instance: info.instance,
|
||||||
|
physical_device: info.physical_device,
|
||||||
|
device: info.device,
|
||||||
|
queue_family_index: info.queue_family_index,
|
||||||
|
queue_index: info.queue_index,
|
||||||
|
};
|
||||||
|
let info = xr::sys::SessionCreateInfo {
|
||||||
|
ty: xr::sys::SessionCreateInfo::TYPE,
|
||||||
|
next: &binding as *const _ as *const _,
|
||||||
|
create_flags: Default::default(),
|
||||||
|
system_id: system,
|
||||||
|
};
|
||||||
|
let mut out = xr::sys::Session::NULL;
|
||||||
|
let x = (instance.fp().create_session)(instance.as_raw(), &info, &mut out);
|
||||||
|
if x.into_raw() >= 0 {
|
||||||
|
Ok(out)
|
||||||
|
} else {
|
||||||
|
Err(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn hmd_pose_from_views(views: &Vec<xr::View>) -> Affine3A {
|
fn hmd_pose_from_views(views: &Vec<xr::View>) -> Affine3A {
|
||||||
let pos = {
|
let pos = {
|
||||||
|
|||||||
Reference in New Issue
Block a user