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(stage.clone());
|
||||
commands.insert_resource(frame_stream.clone());
|
||||
commands.insert_resource(swapchain.clone());
|
||||
commands.insert_resource(XrRenderResources {
|
||||
session,
|
||||
frame_stream,
|
||||
|
||||
@@ -33,7 +33,7 @@ impl<'a> SwapchainSubImage<'a> {
|
||||
pub fn swapchain(mut self, value: &'a XrSwapchain) -> Self {
|
||||
graphics_match!(
|
||||
&value.0;
|
||||
swap => self.inner.swapchain = swap.lock().unwrap().as_raw()
|
||||
swap => self.inner.swapchain = swap.as_raw()
|
||||
);
|
||||
self.swapchain = Some(value);
|
||||
self
|
||||
|
||||
@@ -3,6 +3,7 @@ use bevy::{
|
||||
render::{
|
||||
camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews, RenderTarget},
|
||||
extract_resource::ExtractResourcePlugin,
|
||||
renderer::render_system,
|
||||
view::ExtractedView,
|
||||
Render, RenderApp, RenderSet,
|
||||
},
|
||||
@@ -25,7 +26,6 @@ impl Plugin for XrRenderPlugin {
|
||||
(
|
||||
init_views.run_if(resource_added::<XrGraphicsInfo>),
|
||||
wait_frame.run_if(session_started),
|
||||
insert_texture_views.run_if(session_started),
|
||||
locate_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(
|
||||
Render,
|
||||
(
|
||||
// (insert_texture_views)
|
||||
// .chain()
|
||||
// .in_set(RenderSet::PrepareAssets),
|
||||
(locate_views, update_views_render_world)
|
||||
(
|
||||
insert_texture_views,
|
||||
locate_views,
|
||||
update_views_render_world,
|
||||
)
|
||||
.chain()
|
||||
.in_set(RenderSet::PrepareAssets),
|
||||
wait_image.in_set(RenderSet::Render).before(render_system),
|
||||
(end_frame).chain().in_set(RenderSet::Cleanup),
|
||||
)
|
||||
.run_if(session_started),
|
||||
@@ -277,17 +279,16 @@ fn calculate_projection(near_z: f32, fov: openxr::Fovf) -> Mat4 {
|
||||
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(
|
||||
swapchain_images: Res<XrSwapchainImages>,
|
||||
swapchain: ResMut<XrSwapchain>,
|
||||
mut swapchain: ResMut<XrSwapchain>,
|
||||
mut manual_texture_views: ResMut<ManualTextureViews>,
|
||||
graphics_info: Res<XrGraphicsInfo>,
|
||||
) {
|
||||
let _span = info_span!("xr_insert_texture_views");
|
||||
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];
|
||||
|
||||
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(
|
||||
manual_texture_views: &mut ManualTextureViews,
|
||||
texture: &wgpu::Texture,
|
||||
@@ -323,7 +330,7 @@ pub fn begin_frame(frame_stream: ResMut<XrFrameStream>) {
|
||||
|
||||
pub fn end_frame(
|
||||
frame_stream: ResMut<XrFrameStream>,
|
||||
swapchain: ResMut<XrSwapchain>,
|
||||
mut swapchain: ResMut<XrSwapchain>,
|
||||
stage: Res<XrStage>,
|
||||
display_time: Res<XrTime>,
|
||||
graphics_info: Res<XrGraphicsInfo>,
|
||||
|
||||
@@ -134,7 +134,7 @@ impl XrSession {
|
||||
pub fn create_swapchain(&self, info: SwapchainCreateInfo) -> Result<XrSwapchain> {
|
||||
Ok(XrSwapchain(graphics_match!(
|
||||
&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)]
|
||||
pub struct XrFrameWaiter(pub openxr::FrameWaiter);
|
||||
|
||||
#[derive(Resource, Clone)]
|
||||
#[derive(Resource)]
|
||||
pub struct XrSwapchain(pub(crate) GraphicsWrap<Self>);
|
||||
|
||||
impl GraphicsType for XrSwapchain {
|
||||
type Inner<G: GraphicsExt> = Arc<Mutex<openxr::Swapchain<G>>>;
|
||||
type Inner<G: GraphicsExt> = openxr::Swapchain<G>;
|
||||
}
|
||||
|
||||
impl XrSwapchain {
|
||||
pub fn acquire_image(&self) -> Result<u32> {
|
||||
pub fn acquire_image(&mut self) -> Result<u32> {
|
||||
graphics_match!(
|
||||
&self.0;
|
||||
swap => Ok(swap.lock().unwrap().acquire_image()?)
|
||||
&mut self.0;
|
||||
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!(
|
||||
&self.0;
|
||||
swap => Ok(swap.lock().unwrap().wait_image(timeout)?)
|
||||
&mut self.0;
|
||||
swap => Ok(swap.wait_image(timeout)?)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn release_image(&self) -> Result<()> {
|
||||
pub fn release_image(&mut self) -> Result<()> {
|
||||
graphics_match!(
|
||||
&self.0;
|
||||
swap => Ok(swap.lock().unwrap().release_image()?)
|
||||
&mut self.0;
|
||||
swap => Ok(swap.release_image()?)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -227,7 +227,6 @@ impl XrSwapchain {
|
||||
graphics_match!(
|
||||
&self.0;
|
||||
swap => {
|
||||
let swap = swap.lock().unwrap();
|
||||
let mut images = vec![];
|
||||
for image in swap.enumerate_images()? {
|
||||
unsafe {
|
||||
|
||||
Reference in New Issue
Block a user