moved wait image
This commit is contained in:
@@ -432,7 +432,6 @@ pub fn create_xr_session(
|
|||||||
commands.insert_resource(graphics_info.clone());
|
commands.insert_resource(graphics_info.clone());
|
||||||
commands.insert_resource(stage.clone());
|
commands.insert_resource(stage.clone());
|
||||||
commands.insert_resource(frame_stream.clone());
|
commands.insert_resource(frame_stream.clone());
|
||||||
commands.insert_resource(swapchain.clone());
|
|
||||||
commands.insert_resource(XrRenderResources {
|
commands.insert_resource(XrRenderResources {
|
||||||
session,
|
session,
|
||||||
frame_stream,
|
frame_stream,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ impl<'a> SwapchainSubImage<'a> {
|
|||||||
pub fn swapchain(mut self, value: &'a XrSwapchain) -> Self {
|
pub fn swapchain(mut self, value: &'a XrSwapchain) -> Self {
|
||||||
graphics_match!(
|
graphics_match!(
|
||||||
&value.0;
|
&value.0;
|
||||||
swap => self.inner.swapchain = swap.lock().unwrap().as_raw()
|
swap => self.inner.swapchain = swap.as_raw()
|
||||||
);
|
);
|
||||||
self.swapchain = Some(value);
|
self.swapchain = Some(value);
|
||||||
self
|
self
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use bevy::{
|
|||||||
render::{
|
render::{
|
||||||
camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews, RenderTarget},
|
camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews, RenderTarget},
|
||||||
extract_resource::ExtractResourcePlugin,
|
extract_resource::ExtractResourcePlugin,
|
||||||
|
renderer::render_system,
|
||||||
view::ExtractedView,
|
view::ExtractedView,
|
||||||
Render, RenderApp, RenderSet,
|
Render, RenderApp, RenderSet,
|
||||||
},
|
},
|
||||||
@@ -25,7 +26,6 @@ impl Plugin for XrRenderPlugin {
|
|||||||
(
|
(
|
||||||
init_views.run_if(resource_added::<XrGraphicsInfo>),
|
init_views.run_if(resource_added::<XrGraphicsInfo>),
|
||||||
wait_frame.run_if(session_started),
|
wait_frame.run_if(session_started),
|
||||||
insert_texture_views.run_if(session_started),
|
|
||||||
locate_views.run_if(session_started),
|
locate_views.run_if(session_started),
|
||||||
update_views.run_if(session_started),
|
update_views.run_if(session_started),
|
||||||
)
|
)
|
||||||
@@ -42,12 +42,14 @@ impl Plugin for XrRenderPlugin {
|
|||||||
app.sub_app_mut(RenderApp).add_systems(
|
app.sub_app_mut(RenderApp).add_systems(
|
||||||
Render,
|
Render,
|
||||||
(
|
(
|
||||||
// (insert_texture_views)
|
(
|
||||||
// .chain()
|
insert_texture_views,
|
||||||
// .in_set(RenderSet::PrepareAssets),
|
locate_views,
|
||||||
(locate_views, update_views_render_world)
|
update_views_render_world,
|
||||||
|
)
|
||||||
.chain()
|
.chain()
|
||||||
.in_set(RenderSet::PrepareAssets),
|
.in_set(RenderSet::PrepareAssets),
|
||||||
|
wait_image.in_set(RenderSet::Render).before(render_system),
|
||||||
(end_frame).chain().in_set(RenderSet::Cleanup),
|
(end_frame).chain().in_set(RenderSet::Cleanup),
|
||||||
)
|
)
|
||||||
.run_if(session_started),
|
.run_if(session_started),
|
||||||
@@ -277,17 +279,16 @@ fn calculate_projection(near_z: f32, fov: openxr::Fovf) -> Mat4 {
|
|||||||
Mat4::from_cols_array(&cols)
|
Mat4::from_cols_array(&cols)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// Images inserted into texture views here should not be written to until [`wait_image`] is ran
|
||||||
pub fn insert_texture_views(
|
pub fn insert_texture_views(
|
||||||
swapchain_images: Res<XrSwapchainImages>,
|
swapchain_images: Res<XrSwapchainImages>,
|
||||||
swapchain: ResMut<XrSwapchain>,
|
mut swapchain: ResMut<XrSwapchain>,
|
||||||
mut manual_texture_views: ResMut<ManualTextureViews>,
|
mut manual_texture_views: ResMut<ManualTextureViews>,
|
||||||
graphics_info: Res<XrGraphicsInfo>,
|
graphics_info: Res<XrGraphicsInfo>,
|
||||||
) {
|
) {
|
||||||
let _span = info_span!("xr_insert_texture_views");
|
let _span = info_span!("xr_insert_texture_views");
|
||||||
let index = swapchain.acquire_image().expect("Failed to acquire image");
|
let index = swapchain.acquire_image().expect("Failed to acquire image");
|
||||||
swapchain
|
|
||||||
.wait_image(openxr::Duration::INFINITE)
|
|
||||||
.expect("Failed to wait image");
|
|
||||||
let image = &swapchain_images[index as usize];
|
let image = &swapchain_images[index as usize];
|
||||||
|
|
||||||
for i in 0..2 {
|
for i in 0..2 {
|
||||||
@@ -295,6 +296,12 @@ pub fn insert_texture_views(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn wait_image(mut swapchain: ResMut<XrSwapchain>) {
|
||||||
|
swapchain
|
||||||
|
.wait_image(openxr::Duration::INFINITE)
|
||||||
|
.expect("Failed to wait image");
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_texture_view(
|
pub fn add_texture_view(
|
||||||
manual_texture_views: &mut ManualTextureViews,
|
manual_texture_views: &mut ManualTextureViews,
|
||||||
texture: &wgpu::Texture,
|
texture: &wgpu::Texture,
|
||||||
@@ -323,7 +330,7 @@ pub fn begin_frame(frame_stream: ResMut<XrFrameStream>) {
|
|||||||
|
|
||||||
pub fn end_frame(
|
pub fn end_frame(
|
||||||
frame_stream: ResMut<XrFrameStream>,
|
frame_stream: ResMut<XrFrameStream>,
|
||||||
swapchain: ResMut<XrSwapchain>,
|
mut swapchain: ResMut<XrSwapchain>,
|
||||||
stage: Res<XrStage>,
|
stage: Res<XrStage>,
|
||||||
display_time: Res<XrTime>,
|
display_time: Res<XrTime>,
|
||||||
graphics_info: Res<XrGraphicsInfo>,
|
graphics_info: Res<XrGraphicsInfo>,
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ impl XrSession {
|
|||||||
pub fn create_swapchain(&self, info: SwapchainCreateInfo) -> Result<XrSwapchain> {
|
pub fn create_swapchain(&self, info: SwapchainCreateInfo) -> Result<XrSwapchain> {
|
||||||
Ok(XrSwapchain(graphics_match!(
|
Ok(XrSwapchain(graphics_match!(
|
||||||
&self.1;
|
&self.1;
|
||||||
session => Arc::new(Mutex::new(session.create_swapchain(&info.try_into()?)?)) => XrSwapchain
|
session => session.create_swapchain(&info.try_into()?)? => XrSwapchain
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,32 +189,32 @@ impl XrFrameStream {
|
|||||||
#[derive(Resource, Deref, DerefMut)]
|
#[derive(Resource, Deref, DerefMut)]
|
||||||
pub struct XrFrameWaiter(pub openxr::FrameWaiter);
|
pub struct XrFrameWaiter(pub openxr::FrameWaiter);
|
||||||
|
|
||||||
#[derive(Resource, Clone)]
|
#[derive(Resource)]
|
||||||
pub struct XrSwapchain(pub(crate) GraphicsWrap<Self>);
|
pub struct XrSwapchain(pub(crate) GraphicsWrap<Self>);
|
||||||
|
|
||||||
impl GraphicsType for XrSwapchain {
|
impl GraphicsType for XrSwapchain {
|
||||||
type Inner<G: GraphicsExt> = Arc<Mutex<openxr::Swapchain<G>>>;
|
type Inner<G: GraphicsExt> = openxr::Swapchain<G>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XrSwapchain {
|
impl XrSwapchain {
|
||||||
pub fn acquire_image(&self) -> Result<u32> {
|
pub fn acquire_image(&mut self) -> Result<u32> {
|
||||||
graphics_match!(
|
graphics_match!(
|
||||||
&self.0;
|
&mut self.0;
|
||||||
swap => Ok(swap.lock().unwrap().acquire_image()?)
|
swap => Ok(swap.acquire_image()?)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wait_image(&self, timeout: openxr::Duration) -> Result<()> {
|
pub fn wait_image(&mut self, timeout: openxr::Duration) -> Result<()> {
|
||||||
graphics_match!(
|
graphics_match!(
|
||||||
&self.0;
|
&mut self.0;
|
||||||
swap => Ok(swap.lock().unwrap().wait_image(timeout)?)
|
swap => Ok(swap.wait_image(timeout)?)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn release_image(&self) -> Result<()> {
|
pub fn release_image(&mut self) -> Result<()> {
|
||||||
graphics_match!(
|
graphics_match!(
|
||||||
&self.0;
|
&mut self.0;
|
||||||
swap => Ok(swap.lock().unwrap().release_image()?)
|
swap => Ok(swap.release_image()?)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,7 +227,6 @@ impl XrSwapchain {
|
|||||||
graphics_match!(
|
graphics_match!(
|
||||||
&self.0;
|
&self.0;
|
||||||
swap => {
|
swap => {
|
||||||
let swap = swap.lock().unwrap();
|
|
||||||
let mut images = vec![];
|
let mut images = vec![];
|
||||||
for image in swap.enumerate_images()? {
|
for image in swap.enumerate_images()? {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|||||||
Reference in New Issue
Block a user