Merge pull request #114 from awtterpip/judder-fix-pipelined

Judder fix pipelined
This commit is contained in:
piper
2024-06-05 00:13:10 +02:00
committed by GitHub
2 changed files with 49 additions and 4 deletions

View File

@@ -37,17 +37,21 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
let mut white: StandardMaterial = Color::WHITE.into();
white.unlit = true;
// circular base // circular base
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Circle::new(4.0)), mesh: meshes.add(Circle::new(4.0)),
material: materials.add(Color::WHITE), material: materials.add(white),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default() ..default()
}); });
let mut cube_mat: StandardMaterial = Color::rgb_u8(124, 144, 255).into();
cube_mat.unlit = true;
// cube // cube
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::rgb_u8(124, 144, 255)), material: materials.add(cube_mat),
transform: Transform::from_xyz(0.0, 0.5, 0.0), transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default() ..default()
}); });

View File

@@ -1,13 +1,15 @@
use bevy::{ use bevy::{
ecs::query::QuerySingleError, app::{MainScheduleOrder, SubApp},
ecs::{query::QuerySingleError, schedule::MainThreadExecutor},
prelude::*, prelude::*,
render::{ render::{
camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews, RenderTarget}, camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews, RenderTarget},
extract_resource::ExtractResourcePlugin, extract_resource::ExtractResourcePlugin,
pipelined_rendering::PipelinedRenderingPlugin, pipelined_rendering::{PipelinedRenderingPlugin, RenderAppChannels, RenderExtractApp},
view::ExtractedView, view::ExtractedView,
Render, RenderApp, RenderSet, Render, RenderApp, RenderSet,
}, },
tasks::ComputeTaskPool,
}; };
use bevy_xr::camera::{XrCamera, XrCameraBundle, XrProjection}; use bevy_xr::camera::{XrCamera, XrCameraBundle, XrProjection};
use openxr::ViewStateFlags; use openxr::ViewStateFlags;
@@ -30,6 +32,20 @@ impl Plugin for OxrRenderPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
if app.is_plugin_added::<PipelinedRenderingPlugin>() { if app.is_plugin_added::<PipelinedRenderingPlugin>() {
app.init_resource::<Pipelined>(); app.init_resource::<Pipelined>();
let mut schedule_order = app.world.resource_mut::<MainScheduleOrder>();
if let Some(pos) = schedule_order
.labels
.iter()
.position(|label| (**label).eq(&OxrLast))
{
schedule_order.labels.remove(pos);
}
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(( app.add_plugins((
@@ -138,6 +154,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 const XR_TEXTURE_INDEX: u32 = 3383858418;
pub fn init_views( pub fn init_views(