small changes
This commit is contained in:
@@ -10,11 +10,11 @@ linked = ["openxr/linked"]
|
||||
[dependencies]
|
||||
ash = "0.37.3"
|
||||
futures = "0.3.29"
|
||||
glam = "0.25.0"
|
||||
glam = "0.24.1"
|
||||
thiserror = "1.0.51"
|
||||
tracing = "0.1.40"
|
||||
wgpu = "0.18"
|
||||
wgpu-hal = "0.18"
|
||||
wgpu = "0.17.1"
|
||||
wgpu-hal = "0.17.1"
|
||||
|
||||
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
||||
openxr = "0.17.1"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use glam::UVec2;
|
||||
use wgpu::{Adapter, AdapterInfo, Device, Queue, TextureView};
|
||||
|
||||
use crate::prelude::*;
|
||||
@@ -30,15 +31,23 @@ pub trait SessionTrait {
|
||||
fn begin_frame(&self) -> Result<(View, View)>;
|
||||
/// Submits rendering work for this frame.
|
||||
fn end_frame(&self) -> Result<()>;
|
||||
/// Gets the resolution of a single eye.
|
||||
fn resolution(&self) -> UVec2;
|
||||
/// Gets the texture format for the session.
|
||||
fn format(&self) -> wgpu::TextureFormat;
|
||||
}
|
||||
|
||||
pub trait ViewTrait {
|
||||
/// Returns the [TextureView] used to render this view.
|
||||
fn texture_view(&self) -> TextureView;
|
||||
fn texture_view(&self) -> Option<TextureView>;
|
||||
/// Returns the [Pose] representing the current position of this view.
|
||||
fn pose(&self) -> Pose;
|
||||
/// Returns the projection matrix for the current view.
|
||||
fn projection_matrix(&self) -> glam::Mat4;
|
||||
/// Gets the resolution for this view.
|
||||
fn resolution(&self) -> UVec2;
|
||||
/// Gets the texture format for the view.
|
||||
fn format(&self) -> wgpu::TextureFormat;
|
||||
}
|
||||
|
||||
pub trait InputTrait {
|
||||
|
||||
@@ -92,6 +92,7 @@ pub struct OXrSession {
|
||||
pub(crate) head: openxr::Space,
|
||||
pub(crate) resolution: UVec2,
|
||||
pub(crate) blend_mode: EnvironmentBlendMode,
|
||||
pub(crate) format: wgpu::TextureFormat,
|
||||
}
|
||||
|
||||
impl SessionTrait for OXrSession {
|
||||
@@ -164,6 +165,15 @@ impl SessionTrait for OXrSession {
|
||||
let _span = info_span!("xr_begin_frame").entered();
|
||||
self.swapchain.begin().unwrap()
|
||||
}
|
||||
|
||||
{
|
||||
let _span = info_span!("xr_acquire_image").entered();
|
||||
self.swapchain.acquire_image().unwrap()
|
||||
}
|
||||
{
|
||||
let _span = info_span!("xr_wait_image").entered();
|
||||
self.swapchain.wait_image().unwrap();
|
||||
}
|
||||
let views = {
|
||||
let _span = info_span!("xr_locate_views").entered();
|
||||
self.session
|
||||
@@ -175,27 +185,21 @@ impl SessionTrait for OXrSession {
|
||||
.unwrap()
|
||||
.1
|
||||
};
|
||||
|
||||
*self.views.lock().unwrap() = [views[0].clone(), views[1].clone()];
|
||||
|
||||
{
|
||||
let _span = info_span!("xr_acquire_image").entered();
|
||||
self.swapchain.acquire_image().unwrap()
|
||||
}
|
||||
{
|
||||
let _span = info_span!("xr_wait_image").entered();
|
||||
self.swapchain.wait_image().unwrap();
|
||||
}
|
||||
{
|
||||
let _span = info_span!("xr_update_manual_texture_views").entered();
|
||||
let (left, right) = self.swapchain.get_render_views();
|
||||
let left = OXrView {
|
||||
texture: Mutex::new(Some(left)),
|
||||
view: views[0],
|
||||
resolution: self.resolution,
|
||||
format: self.format,
|
||||
};
|
||||
let right = OXrView {
|
||||
texture: Mutex::new(Some(right)),
|
||||
view: views[1],
|
||||
resolution: self.resolution,
|
||||
format: self.format,
|
||||
};
|
||||
Ok((left.into(), right.into()))
|
||||
}
|
||||
@@ -208,12 +212,14 @@ impl SessionTrait for OXrSession {
|
||||
}
|
||||
{
|
||||
let _span = info_span!("xr_end_frame").entered();
|
||||
let frame_state = self.frame_state.lock().unwrap().clone();
|
||||
let result = self.swapchain.end(
|
||||
self.frame_state.lock().unwrap().predicted_display_time,
|
||||
frame_state.predicted_display_time,
|
||||
&*self.views.lock().unwrap(),
|
||||
&self.stage,
|
||||
self.resolution,
|
||||
self.blend_mode,
|
||||
frame_state.should_render,
|
||||
// passthrough_layer.map(|p| p.into_inner()),
|
||||
);
|
||||
match result {
|
||||
@@ -223,16 +229,26 @@ impl SessionTrait for OXrSession {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn resolution(&self) -> UVec2 {
|
||||
self.resolution
|
||||
}
|
||||
|
||||
fn format(&self) -> wgpu::TextureFormat {
|
||||
self.format
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OXrView {
|
||||
texture: Mutex<Option<wgpu::TextureView>>,
|
||||
view: openxr::View,
|
||||
resolution: UVec2,
|
||||
format: wgpu::TextureFormat,
|
||||
}
|
||||
|
||||
impl ViewTrait for OXrView {
|
||||
fn texture_view(&self) -> wgpu::TextureView {
|
||||
std::mem::take(&mut *self.texture.lock().unwrap()).unwrap()
|
||||
fn texture_view(&self) -> Option<wgpu::TextureView> {
|
||||
std::mem::take(&mut *self.texture.lock().unwrap())
|
||||
}
|
||||
|
||||
fn pose(&self) -> Pose {
|
||||
@@ -336,8 +352,34 @@ impl ViewTrait for OXrView {
|
||||
|
||||
Mat4::from_cols_array(&cols)
|
||||
}
|
||||
|
||||
fn resolution(&self) -> UVec2 {
|
||||
self.resolution
|
||||
}
|
||||
|
||||
fn format(&self) -> wgpu::TextureFormat {
|
||||
self.format
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OXrInput {
|
||||
action_set: openxr::ActionSet,
|
||||
}
|
||||
|
||||
impl InputTrait for OXrInput {
|
||||
fn get_haptics(&self, path: ActionPath) -> Result<Action<Haptic>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_pose(&self, path: ActionPath) -> Result<Action<Pose>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_float(&self, path: ActionPath) -> Result<Action<f32>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_bool(&self, path: ActionPath) -> Result<Action<bool>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ impl Swapchain {
|
||||
stage: &openxr::Space,
|
||||
resolution: UVec2,
|
||||
environment_blend_mode: openxr::EnvironmentBlendMode,
|
||||
should_render: bool,
|
||||
) -> Result<()> {
|
||||
Ok(match self {
|
||||
Swapchain::Vulkan(swapchain) => swapchain.end(
|
||||
@@ -73,6 +74,7 @@ impl Swapchain {
|
||||
stage,
|
||||
resolution,
|
||||
environment_blend_mode,
|
||||
should_render,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
@@ -132,6 +134,7 @@ impl<G: openxr::Graphics> SwapchainInner<G> {
|
||||
stage: &openxr::Space,
|
||||
resolution: UVec2,
|
||||
environment_blend_mode: openxr::EnvironmentBlendMode,
|
||||
should_render: bool,
|
||||
) -> openxr::Result<()> {
|
||||
let rect = openxr::Rect2Di {
|
||||
offset: openxr::Offset2Di { x: 0, y: 0 },
|
||||
@@ -145,31 +148,36 @@ impl<G: openxr::Graphics> SwapchainInner<G> {
|
||||
warn!("views are len of 0");
|
||||
return Ok(());
|
||||
}
|
||||
self.stream.lock().unwrap().end(
|
||||
predicted_display_time,
|
||||
environment_blend_mode,
|
||||
&[&openxr::CompositionLayerProjection::new()
|
||||
.space(stage)
|
||||
.views(&[
|
||||
openxr::CompositionLayerProjectionView::new()
|
||||
.pose(views[0].pose)
|
||||
.fov(views[0].fov)
|
||||
.sub_image(
|
||||
openxr::SwapchainSubImage::new()
|
||||
.swapchain(&swapchain)
|
||||
.image_array_index(0)
|
||||
.image_rect(rect),
|
||||
),
|
||||
openxr::CompositionLayerProjectionView::new()
|
||||
.pose(views[1].pose)
|
||||
.fov(views[1].fov)
|
||||
.sub_image(
|
||||
openxr::SwapchainSubImage::new()
|
||||
.swapchain(&swapchain)
|
||||
.image_array_index(1)
|
||||
.image_rect(rect),
|
||||
),
|
||||
])],
|
||||
)
|
||||
let mut stream = self.stream.lock().unwrap();
|
||||
if true {
|
||||
stream.end(
|
||||
predicted_display_time,
|
||||
environment_blend_mode,
|
||||
&[&openxr::CompositionLayerProjection::new()
|
||||
.space(stage)
|
||||
.views(&[
|
||||
openxr::CompositionLayerProjectionView::new()
|
||||
.pose(views[0].pose)
|
||||
.fov(views[0].fov)
|
||||
.sub_image(
|
||||
openxr::SwapchainSubImage::new()
|
||||
.swapchain(&swapchain)
|
||||
.image_array_index(0)
|
||||
.image_rect(rect),
|
||||
),
|
||||
openxr::CompositionLayerProjectionView::new()
|
||||
.pose(views[1].pose)
|
||||
.fov(views[1].fov)
|
||||
.sub_image(
|
||||
openxr::SwapchainSubImage::new()
|
||||
.swapchain(&swapchain)
|
||||
.image_array_index(1)
|
||||
.image_rect(rect),
|
||||
),
|
||||
])],
|
||||
)
|
||||
} else {
|
||||
stream.end(predicted_display_time, environment_blend_mode, &[])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ pub fn init_oxr_graphics(
|
||||
}
|
||||
|
||||
let vk_entry = unsafe { ash::Entry::load() }.map_err(|_| XrError::Placeholder)?;
|
||||
let flags = wgpu::InstanceFlags::empty();
|
||||
let extensions = <V as Api>::Instance::desired_extensions(&vk_entry, vk_target_version, flags)
|
||||
let flags = wgpu_hal::InstanceFlags::empty();
|
||||
let extensions = <V as Api>::Instance::required_extensions(&vk_entry, vk_target_version, flags)
|
||||
.map_err(|_| XrError::Placeholder)?;
|
||||
let device_extensions = vec![
|
||||
ash::extensions::khr::Swapchain::name(),
|
||||
@@ -317,6 +317,7 @@ pub fn init_oxr_graphics(
|
||||
.create_reference_space(openxr::ReferenceSpaceType::STAGE, openxr::Posef::IDENTITY)?,
|
||||
head: session
|
||||
.create_reference_space(openxr::ReferenceSpaceType::VIEW, openxr::Posef::IDENTITY)?,
|
||||
format: swapchain_format,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -356,7 +357,7 @@ fn wgpu_to_vulkan(format: wgpu::TextureFormat) -> Option<vk::Format> {
|
||||
Tf::Bgra8Unorm => F::B8G8R8A8_UNORM,
|
||||
Tf::Rgba8Uint => F::R8G8B8A8_UINT,
|
||||
Tf::Rgba8Sint => F::R8G8B8A8_SINT,
|
||||
Tf::Rgb10a2Uint => F::A2B10G10R10_UINT_PACK32,
|
||||
// Tf::Rgb10a2Uint => F::A2B10G10R10_UINT_PACK32,
|
||||
Tf::Rgb10a2Unorm => F::A2B10G10R10_UNORM_PACK32,
|
||||
Tf::Rg11b10Float => F::B10G11R11_UFLOAT_PACK32,
|
||||
Tf::Rg32Uint => F::R32G32_UINT,
|
||||
|
||||
@@ -11,6 +11,6 @@ pub enum XrError {
|
||||
|
||||
impl Display for XrError {
|
||||
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
todo!()
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user