move wait frame to after render app finishes

This commit is contained in:
awtterpip
2024-06-02 18:16:22 -05:00
parent eddff879c4
commit 41399d83a9
3 changed files with 37 additions and 6 deletions

View File

@@ -150,9 +150,9 @@ impl Plugin for OxrInitPlugin {
.insert_non_send_resource(session_create_info)
.configure_sets(OxrLast, OxrHandleEvents);
app.world
.resource_mut::<MainScheduleOrder>()
.insert_after(Last, OxrLast);
// app.world
// .resource_mut::<MainScheduleOrder>()
// .insert_after(Last, OxrLast);
app.world
.spawn((TransformBundle::default(), OxrTrackingRoot));

View File

@@ -34,7 +34,7 @@ pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
plugins
.build()
.disable::<RenderPlugin>()
.disable::<PipelinedRenderingPlugin>()
// .disable::<PipelinedRenderingPlugin>()
.add_before::<RenderPlugin, _>(XrSessionPlugin)
.add_before::<RenderPlugin, _>(OxrInitPlugin::default())
.add(OxrReferenceSpacePlugin::default())

View File

@@ -1,13 +1,15 @@
use bevy::{
ecs::query::QuerySingleError,
app::SubApp,
ecs::{query::QuerySingleError, schedule::MainThreadExecutor},
prelude::*,
render::{
camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews, RenderTarget},
extract_resource::ExtractResourcePlugin,
pipelined_rendering::PipelinedRenderingPlugin,
pipelined_rendering::{PipelinedRenderingPlugin, RenderAppChannels, RenderExtractApp},
view::ExtractedView,
Render, RenderApp, RenderSet,
},
tasks::ComputeTaskPool,
};
use bevy_xr::camera::{XrCamera, XrCameraBundle, XrProjection};
use openxr::ViewStateFlags;
@@ -30,6 +32,10 @@ impl Plugin for OxrRenderPlugin {
fn build(&self, app: &mut App) {
if app.is_plugin_added::<PipelinedRenderingPlugin>() {
app.init_resource::<Pipelined>();
if let Some(sub_app) = app.remove_sub_app(RenderExtractApp) {
app.insert_sub_app(RenderExtractApp, SubApp::new(sub_app.app, update_rendering));
}
}
app.add_plugins((
@@ -138,6 +144,31 @@ impl Plugin for OxrRenderPlugin {
}
}
// This function waits for the rendering world to be received,
// runs extract, and then sends the rendering world back to the render thread.
//
// modified pipelined rendering extract function
fn update_rendering(app_world: &mut World, _sub_app: &mut App) {
app_world.resource_scope(|world, main_thread_executor: Mut<MainThreadExecutor>| {
world.resource_scope(|world, mut render_channels: Mut<RenderAppChannels>| {
// we use a scope here to run any main thread tasks that the render world still needs to run
// while we wait for the render world to be received.
let mut render_app = ComputeTaskPool::get()
.scope_with_executor(true, Some(&*main_thread_executor.0), |s| {
s.spawn(async { render_channels.recv().await });
})
.pop()
.unwrap();
world.run_schedule(OxrLast);
render_app.extract(world);
render_channels.send_blocking(render_app);
});
});
}
pub const XR_TEXTURE_INDEX: u32 = 3383858418;
pub fn init_views(