feat: impl Pipelined Rendering
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
17
src/main.rs
17
src/main.rs
@@ -29,6 +29,9 @@ use bevy::gizmos::GizmoPlugin;
|
||||
use bevy::gltf::GltfPlugin;
|
||||
use bevy::input::InputPlugin;
|
||||
use bevy::pbr::PbrPlugin;
|
||||
use bevy::render::pipelined_rendering::{
|
||||
PipelinedRenderThreadOnCreateCallback, PipelinedRenderingPlugin,
|
||||
};
|
||||
use bevy::render::settings::{Backends, RenderCreation, WgpuSettings};
|
||||
use bevy::render::{RenderDebugFlags, RenderPlugin};
|
||||
use bevy::scene::ScenePlugin;
|
||||
@@ -335,6 +338,9 @@ fn bevy_loop(
|
||||
false => plugins.add(FlatscreenInputPlugin),
|
||||
};
|
||||
}
|
||||
app.insert_resource(PipelinedRenderThreadOnCreateCallback(
|
||||
enter_runtime_context.clone(),
|
||||
));
|
||||
app.add_plugins(
|
||||
if !args.force_flatscreen {
|
||||
add_xr_plugins(plugins)
|
||||
@@ -386,6 +392,7 @@ fn bevy_loop(
|
||||
..default()
|
||||
}),
|
||||
);
|
||||
app.add_plugins(PipelinedRenderingPlugin);
|
||||
|
||||
app.add_plugins(bevy_sk::hand::HandPlugin);
|
||||
app.add_plugins(bevy_equirect::EquirectangularPlugin);
|
||||
@@ -506,3 +513,13 @@ fn xr_step(world: &mut World) {
|
||||
|
||||
tick_internal_client();
|
||||
}
|
||||
|
||||
pub fn get_time(pipelined: bool, state: &OxrFrameState) -> openxr::Time {
|
||||
if pipelined {
|
||||
openxr::Time::from_nanos(
|
||||
state.predicted_display_time.as_nanos() + state.predicted_display_period.as_nanos(),
|
||||
)
|
||||
} else {
|
||||
state.predicted_display_time
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
use bevy::prelude::*;
|
||||
use bevy_mod_openxr::{
|
||||
helper_traits::{ToQuat as _, ToVec3 as _},
|
||||
resources::OxrFrameState,
|
||||
resources::{OxrFrameState, Pipelined},
|
||||
session::OxrSession,
|
||||
};
|
||||
use bevy_mod_xr::{
|
||||
@@ -12,7 +12,7 @@ use bevy_mod_xr::{
|
||||
};
|
||||
use openxr::SpaceLocationFlags;
|
||||
|
||||
use crate::{DbusConnection, PreFrameWait, nodes::spatial::Spatial};
|
||||
use crate::{DbusConnection, PreFrameWait, get_time, nodes::spatial::Spatial};
|
||||
|
||||
use super::{ObjectHandle, SpatialRef, input::mouse_pointer::FlatscreenCam};
|
||||
|
||||
@@ -68,6 +68,7 @@ fn update_xr(
|
||||
ref_space: Option<Res<XrPrimaryReferenceSpace>>,
|
||||
hmd: Res<Hmd>,
|
||||
state: Option<Res<OxrFrameState>>,
|
||||
pipelined: Option<Res<Pipelined>>,
|
||||
) {
|
||||
let (Some(session), Some(view), Some(ref_space), Some(state)) =
|
||||
(session, hmd.space, ref_space, state)
|
||||
@@ -80,9 +81,9 @@ fn update_xr(
|
||||
// });
|
||||
return;
|
||||
};
|
||||
// this won't be correct with pipelined rendering
|
||||
let time = get_time(pipelined.is_some(), &state);
|
||||
let location = session
|
||||
.locate_space(&view, &ref_space, state.predicted_display_time)
|
||||
.locate_space(&view, &ref_space, time)
|
||||
.inspect_err(|err| error!("Error while Locating OpenXR Stage Space {err}"));
|
||||
if let Ok(location) = location {
|
||||
let is_tracked = location
|
||||
|
||||
@@ -2,6 +2,7 @@ use super::{CaptureManager, get_sorted_handlers};
|
||||
use crate::{
|
||||
DbusConnection, PreFrameWait,
|
||||
core::client::INTERNAL_CLIENT,
|
||||
get_time,
|
||||
nodes::{
|
||||
Node, OwnedNode,
|
||||
drawable::{
|
||||
@@ -19,7 +20,7 @@ use bevy::{math::Affine3, prelude::*};
|
||||
use bevy_mod_openxr::{
|
||||
action_binding::{OxrSendActionBindings, OxrSuggestActionBinding},
|
||||
helper_traits::{ToIsometry3d, ToVec2},
|
||||
resources::{OxrFrameState, OxrInstance},
|
||||
resources::{OxrFrameState, OxrInstance, Pipelined},
|
||||
session::OxrSession,
|
||||
};
|
||||
use bevy_mod_xr::{
|
||||
@@ -147,6 +148,7 @@ fn update(
|
||||
session: Option<Res<OxrSession>>,
|
||||
ref_space: Option<Res<XrPrimaryReferenceSpace>>,
|
||||
state: Option<Res<OxrFrameState>>,
|
||||
pipelined: Option<Res<Pipelined>>,
|
||||
) {
|
||||
let (Some(session), Some(state), Some(ref_space)) = (session, state, ref_space) else {
|
||||
controllers.left.set_enabled(false);
|
||||
@@ -158,8 +160,7 @@ fn update(
|
||||
.sync_actions(&[ActiveActionSet::new(&actions.set)])
|
||||
.unwrap();
|
||||
});
|
||||
let time = state.predicted_display_time;
|
||||
// stupid bevy gltf loading issue (rotated 180 degrees on the y axis)
|
||||
let time = get_time(pipelined.is_some(), &state);
|
||||
controllers
|
||||
.left
|
||||
.update(&session, &actions, time, ref_space.0);
|
||||
|
||||
@@ -8,11 +8,11 @@ use crate::nodes::{
|
||||
spatial::Spatial,
|
||||
};
|
||||
use crate::objects::{AsyncTracked, ObjectHandle, SpatialRef, Tracked};
|
||||
use crate::{BevyMaterial, DbusConnection, ObjectRegistryRes, PreFrameWait};
|
||||
use crate::{BevyMaterial, DbusConnection, ObjectRegistryRes, PreFrameWait, get_time};
|
||||
use bevy::prelude::Transform as BevyTransform;
|
||||
use bevy::prelude::*;
|
||||
use bevy_mod_openxr::helper_traits::{ToQuat, ToVec3};
|
||||
use bevy_mod_openxr::resources::OxrFrameState;
|
||||
use bevy_mod_openxr::resources::{OxrFrameState, Pipelined};
|
||||
use bevy_mod_openxr::session::OxrSession;
|
||||
use bevy_mod_xr::hands::{HandBone, HandSide, XrHandBoneEntities, XrHandBoneRadius};
|
||||
use bevy_mod_xr::session::{XrPreDestroySession, XrSessionCreated};
|
||||
@@ -50,6 +50,7 @@ fn update_hands(
|
||||
&mut XrHandBoneRadius,
|
||||
)>,
|
||||
joints_query: Query<&XrHandBoneEntities>,
|
||||
pipelined: Option<Res<Pipelined>>,
|
||||
) {
|
||||
let (Some(session), Some(state), Some(ref_space)) = (session, state, ref_space) else {
|
||||
hands.left.tracked.set_tracked(false);
|
||||
@@ -62,9 +63,9 @@ fn update_hands(
|
||||
hand.tracked.set_tracked(false);
|
||||
return None;
|
||||
};
|
||||
// this won't be correct with pipelined rendering
|
||||
let time = get_time(pipelined.is_some(), &state);
|
||||
session
|
||||
.locate_hand_joints(tracker, &ref_space, state.predicted_display_time)
|
||||
.locate_hand_joints(tracker, &ref_space, time)
|
||||
.inspect_err(|err| error!("Error while locating hand joints"))
|
||||
.ok()
|
||||
.flatten()
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
use bevy::prelude::*;
|
||||
use bevy_mod_openxr::{
|
||||
helper_traits::{ToQuat, ToVec3},
|
||||
resources::OxrFrameState,
|
||||
resources::{OxrFrameState, Pipelined},
|
||||
session::OxrSession,
|
||||
};
|
||||
use bevy_mod_xr::{
|
||||
@@ -14,7 +14,7 @@ use openxr::SpaceLocationFlags;
|
||||
use parking_lot::RwLock;
|
||||
use zbus::{Connection, ObjectServer, interface};
|
||||
|
||||
use crate::{DbusConnection, PreFrameWait, nodes::spatial::Spatial};
|
||||
use crate::{DbusConnection, PreFrameWait, get_time, nodes::spatial::Spatial};
|
||||
|
||||
use super::{AsyncTracked, ObjectHandle, SpatialRef, Tracked};
|
||||
|
||||
@@ -75,6 +75,7 @@ fn update(
|
||||
ref_space: Option<Res<XrPrimaryReferenceSpace>>,
|
||||
play_space: Res<PlaySpace>,
|
||||
state: Option<Res<OxrFrameState>>,
|
||||
pipelined: Option<Res<Pipelined>>,
|
||||
) {
|
||||
let (Some(session), Some(stage), Some(ref_space), Some(state)) =
|
||||
(session, stage, ref_space, state)
|
||||
@@ -87,9 +88,9 @@ fn update(
|
||||
.set_local_transform(Mat4::from_translation(vec3(0.0, -1.65, 0.0)));
|
||||
return;
|
||||
};
|
||||
// this won't be correct with pipelined rendering
|
||||
let time = get_time(pipelined.is_some(), &state);
|
||||
let location = session
|
||||
.locate_space(&stage.0, &ref_space, state.predicted_display_time)
|
||||
.locate_space(&stage.0, &ref_space, time)
|
||||
.inspect_err(|err| error!("Error while Locating OpenXR Stage Space {err}"));
|
||||
if let Ok(location) = location {
|
||||
let is_tracked = location.location_flags.contains(
|
||||
|
||||
@@ -11,6 +11,7 @@ mod xdg;
|
||||
|
||||
use crate::core::error::ServerError;
|
||||
use crate::core::registry::OwnedRegistry;
|
||||
use crate::get_time;
|
||||
use crate::nodes::drawable::model::ModelNodeSystemSet;
|
||||
use crate::wayland::core::seat::SeatMessage;
|
||||
use crate::wayland::core::surface::Surface;
|
||||
@@ -26,7 +27,7 @@ use bevy::render::{Render, RenderApp};
|
||||
use bevy::{asset::Assets, ecs::resource::Resource, image::Image};
|
||||
use bevy_dmabuf::import::ImportedDmatexs;
|
||||
use bevy_mod_openxr::render::end_frame;
|
||||
use bevy_mod_openxr::resources::{OxrFrameState, OxrInstance};
|
||||
use bevy_mod_openxr::resources::{OxrFrameState, OxrInstance, Pipelined};
|
||||
use bevy_mod_xr::session::XrRenderSet;
|
||||
use core::buffer::BufferUsage;
|
||||
use core::{buffer::Buffer, callback::Callback, surface::WL_SURFACE_REGISTRY};
|
||||
@@ -490,6 +491,7 @@ fn submit_frame_timings(
|
||||
mut frame_count: Local<u64>,
|
||||
instance: Option<Res<OxrInstance>>,
|
||||
frame_state: Option<Res<OxrFrameState>>,
|
||||
pipelined: Option<Res<Pipelined>>,
|
||||
) {
|
||||
*frame_count += 1;
|
||||
let display_timestamp = frame_state
|
||||
@@ -502,7 +504,7 @@ fn submit_frame_timings(
|
||||
let mut out = MaybeUninit::uninit();
|
||||
let result = (v.convert_time_to_timespec_time)(
|
||||
instance.as_raw(),
|
||||
state.predicted_display_time,
|
||||
get_time(pipelined.is_some(), &state),
|
||||
out.as_mut_ptr(),
|
||||
);
|
||||
if result != openxr::sys::Result::SUCCESS {
|
||||
|
||||
Reference in New Issue
Block a user