Skip to content

Commit

Permalink
Avoid extra blit for GL->D3D.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed Mar 4, 2020
1 parent 68b0242 commit 400fbf5
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 279 deletions.
1 change: 1 addition & 0 deletions webxr-api/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub use session::MainThreadSession;
pub use session::Quitter;
pub use session::Session;
pub use session::SessionBuilder;
pub use session::SessionId;
pub use session::SessionInit;
pub use session::SessionMode;
pub use session::SessionThread;
Expand Down
8 changes: 7 additions & 1 deletion webxr-api/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::Receiver;
use crate::Sender;
use crate::Session;
use crate::SessionBuilder;
use crate::SessionId;
use crate::SessionInit;
use crate::SessionMode;
use crate::SwapChainId;
Expand All @@ -39,6 +40,7 @@ pub struct MainThreadRegistry<SwapChains> {
sender: Sender<RegistryMsg>,
receiver: Receiver<RegistryMsg>,
waker: MainThreadWakerImpl,
next_session_id: u32,
}

pub trait MainThreadWaker: 'static + Send {
Expand Down Expand Up @@ -139,6 +141,7 @@ where
sender,
receiver,
waker,
next_session_id: 0,
})
}

Expand Down Expand Up @@ -211,7 +214,10 @@ where
let swap_chains = self.swap_chains.as_mut().ok_or(Error::NoMatchingDevice)?;
for discovery in &mut self.discoveries {
if discovery.supports_session(mode) {
let xr = SessionBuilder::new(swap_chains, &mut self.sessions, raf_sender.clone());
let id = SessionId(self.next_session_id);
self.next_session_id += 1;
let xr =
SessionBuilder::new(swap_chains, &mut self.sessions, raf_sender.clone(), id);
match discovery.request_session(mode, &init, xr) {
Ok(session) => return Ok(session),
Err(err) => warn!("XR device error {:?}", err),
Expand Down
26 changes: 24 additions & 2 deletions webxr-api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,18 @@ pub struct Session {
environment_blend_mode: EnvironmentBlendMode,
initial_inputs: Vec<InputSource>,
granted_features: Vec<String>,
id: SessionId,
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "ipc", derive(Deserialize, Serialize))]
pub struct SessionId(pub(crate) u32);

impl Session {
pub fn id(&self) -> SessionId {
self.id
}

pub fn floor_transform(&self) -> Option<RigidTransform3D<f32, Native, Floor>> {
self.floor_transform.clone()
}
Expand Down Expand Up @@ -204,6 +213,7 @@ pub struct SessionThread<Device, SwapChains: SwapChainsAPI<SwapChainId>> {
frame_sender: Sender<Frame>,
running: bool,
device: Device,
id: SessionId,
}

impl<Device, SwapChains> SessionThread<Device, SwapChains>
Expand All @@ -215,6 +225,7 @@ where
mut device: Device,
swap_chains: SwapChains,
frame_sender: Sender<Frame>,
id: SessionId,
) -> Result<Self, Error> {
let (sender, receiver) = crate::channel().or(Err(Error::CommunicationError))?;
device.set_quitter(Quitter {
Expand All @@ -232,6 +243,7 @@ where
frame_count,
frame_sender,
running,
id,
})
}

Expand All @@ -251,6 +263,7 @@ where
initial_inputs,
environment_blend_mode,
granted_features,
id: self.id,
}
}

Expand Down Expand Up @@ -386,21 +399,28 @@ pub struct SessionBuilder<'a, SwapChains: 'a> {
swap_chains: &'a SwapChains,
sessions: &'a mut Vec<Box<dyn MainThreadSession>>,
frame_sender: Sender<Frame>,
id: SessionId,
}

impl<'a, SwapChains> SessionBuilder<'a, SwapChains>
where
SwapChains: SwapChainsAPI<SwapChainId>,
{
pub fn id(&self) -> SessionId {
self.id
}

pub(crate) fn new(
swap_chains: &'a SwapChains,
sessions: &'a mut Vec<Box<dyn MainThreadSession>>,
frame_sender: Sender<Frame>,
id: SessionId,
) -> Self {
SessionBuilder {
swap_chains,
sessions,
frame_sender,
id,
}
}

Expand All @@ -413,8 +433,10 @@ where
let (acks, ackr) = crate::channel().or(Err(Error::CommunicationError))?;
let swap_chains = self.swap_chains.clone();
let frame_sender = self.frame_sender.clone();
let id = self.id;
thread::spawn(move || {
match factory().and_then(|device| SessionThread::new(device, swap_chains, frame_sender))
match factory()
.and_then(|device| SessionThread::new(device, swap_chains, frame_sender, id))
{
Ok(mut thread) => {
let session = thread.new_session();
Expand All @@ -438,7 +460,7 @@ where
let device = factory()?;
let swap_chains = self.swap_chains.clone();
let frame_sender = self.frame_sender.clone();
let mut session_thread = SessionThread::new(device, swap_chains, frame_sender)?;
let mut session_thread = SessionThread::new(device, swap_chains, frame_sender, self.id)?;
let session = session_thread.new_session();
self.sessions.push(Box::new(session_thread));
Ok(session)
Expand Down
6 changes: 4 additions & 2 deletions webxr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ headless = []
ipc = ["webxr-api/ipc", "serde"]
googlevr = ["gvr-sys", "android_injected_glue", "gles"]
magicleap = ["egl"]
openxr-api = ["angle", "openxr", "winapi", "wio"]
# Enabling the sm-angle-default feature only has an effect on Windows.
openxr-api = ["angle", "openxr", "winapi", "wio", "surfman/sm-angle-default", "surfman/sm-angle-flush"]
profile = ["webxr-api/profile"]

[dependencies]
webxr-api = { path = "../webxr-api" }
crossbeam-channel = "0.4"
euclid = "0.20"
gleam = "0.6"
glutin = { version = "0.21", optional = true }
Expand All @@ -42,7 +44,7 @@ gvr-sys = { version = "0.7", optional = true }
openxr = { version = "0.9.1", optional = true }
serde = { version = "1.0", optional = true }
surfman = { version = "0.1", features = ["sm-osmesa"] }
surfman-chains = "0.2"
surfman-chains = "0.3"
time = "0.1.42"

[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
Loading

0 comments on commit 400fbf5

Please sign in to comment.