Skip to content

Commit

Permalink
add headless graphics api
Browse files Browse the repository at this point in the history
  • Loading branch information
galister committed Aug 10, 2024
1 parent 2af2256 commit 41e1171
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
66 changes: 66 additions & 0 deletions openxr/src/graphics/headless.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use crate::*;

/// Used to create a session without graphics.
///
/// See [`XR_MND_headless`] for details.
///
/// [`XR_MND_headless`]: https://www.khronos.org/registry/OpenXR/specs/1.1/html/xrspec.html#XR_MND_headless
pub enum Headless {}

impl Graphics for Headless {
type Requirements = Requirements;
type SessionCreateInfo = SessionCreateInfo;
type SwapchainImage = HeadlessSwapchainImage;
type Format = HeadlessFormat;

Check failure on line 14 in openxr/src/graphics/headless.rs

View workflow job for this annotation

GitHub Actions / lint

the trait bound `graphics::headless::HeadlessFormat: std::marker::Copy` is not satisfied

Check failure on line 14 in openxr/src/graphics/headless.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, x86_64-unknown-linux-gnu)

the trait bound `HeadlessFormat: Copy` is not satisfied

Check failure on line 14 in openxr/src/graphics/headless.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, x86_64-unknown-linux-gnu)

the trait bound `HeadlessFormat: Copy` is not satisfied

Check failure on line 14 in openxr/src/graphics/headless.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, aarch64-linux-android)

the trait bound `HeadlessFormat: Copy` is not satisfied

fn raise_format(_: i64) -> Self::Format {
// used by enumerate_swapchain_formats, which returns empty
unreachable!()
}
fn lower_format(_: Self::Format) -> i64 {
// used by create_swapchain, which is not available in headless
unreachable!()
}

fn requirements(_instance: &Instance, _system: SystemId) -> Result<Requirements> {
Ok(Requirements {})
}

unsafe fn create_session(
instance: &Instance,
system: SystemId,
_info: &SessionCreateInfo,
) -> Result<sys::Session> {
let info = sys::SessionCreateInfo {
ty: sys::SessionCreateInfo::TYPE,
next: std::ptr::null(),
create_flags: Default::default(),
system_id: system,
};
let mut out = sys::Session::NULL;
cvt((instance.fp().create_session)(
instance.as_raw(),
&info,
&mut out,
))?;
Ok(out)
}

fn enumerate_swapchain_images(
_swapchain: &Swapchain<Self>,
) -> Result<Vec<Self::SwapchainImage>> {
// in a MND_headless session, xrEnumerateSwapchainFormats will always
// enumerate 0 formats, and so it's not possible to create a swapchain
unreachable!();
}
}

#[derive(Clone, Copy)]
pub struct Requirements {}

#[derive(Clone, Copy)]
pub struct SessionCreateInfo {}

pub enum HeadlessSwapchainImage {}

pub enum HeadlessFormat {}
3 changes: 3 additions & 0 deletions openxr/src/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ pub use opengl::OpenGL;

pub mod opengles;
pub use opengles::OpenGlEs;

pub mod headless;
pub use headless::Headless;

0 comments on commit 41e1171

Please sign in to comment.