Skip to content

Commit 47ed911

Browse files
committed
switch to using first context in webgl thread
1 parent 0f3b0ac commit 47ed911

File tree

8 files changed

+46
-25
lines changed

8 files changed

+46
-25
lines changed

components/shared/webxr/layer.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<GL: GLTypes> LayerGrandManager<GL> {
8080

8181
pub fn create_layer_manager<F, M>(&self, factory: F) -> Result<LayerManager, Error>
8282
where
83-
F: 'static + Send + FnOnce(&mut dyn GLContexts<GL>) -> Result<M, Error>,
83+
F: 'static + Send + FnOnce(&GL::Device, &mut dyn GLContexts<GL>) -> Result<M, Error>,
8484
M: 'static + LayerManagerAPI<GL>,
8585
{
8686
self.0
@@ -172,7 +172,13 @@ impl Drop for LayerManager {
172172

173173
#[allow(clippy::type_complexity)]
174174
pub struct LayerManagerFactory<GL: GLTypes>(
175-
Box<dyn Send + FnOnce(&mut dyn GLContexts<GL>) -> Result<Box<dyn LayerManagerAPI<GL>>, Error>>,
175+
Box<
176+
dyn Send
177+
+ FnOnce(
178+
&GL::Device,
179+
&mut dyn GLContexts<GL>,
180+
) -> Result<Box<dyn LayerManagerAPI<GL>>, Error>,
181+
>,
176182
);
177183

178184
impl<GL: GLTypes> Debug for LayerManagerFactory<GL> {
@@ -184,17 +190,20 @@ impl<GL: GLTypes> Debug for LayerManagerFactory<GL> {
184190
impl<GL: GLTypes> LayerManagerFactory<GL> {
185191
pub fn new<F, M>(factory: F) -> LayerManagerFactory<GL>
186192
where
187-
F: 'static + Send + FnOnce(&mut dyn GLContexts<GL>) -> Result<M, Error>,
193+
F: 'static + Send + FnOnce(&GL::Device, &mut dyn GLContexts<GL>) -> Result<M, Error>,
188194
M: 'static + LayerManagerAPI<GL>,
189195
{
190-
LayerManagerFactory(Box::new(move |contexts| Ok(Box::new(factory(contexts)?))))
196+
LayerManagerFactory(Box::new(move |device, contexts| {
197+
Ok(Box::new(factory(device, contexts)?))
198+
}))
191199
}
192200

193201
pub fn build(
194202
self,
203+
device: &GL::Device,
195204
contexts: &mut dyn GLContexts<GL>,
196205
) -> Result<Box<dyn LayerManagerAPI<GL>>, Error> {
197-
(self.0)(contexts)
206+
(self.0)(device, contexts)
198207
}
199208
}
200209

components/webgl/webgl_thread.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,14 @@ impl WebGLThread {
415415
};
416416
match command {
417417
WebXRCommand::CreateLayerManager(sender) => {
418-
let result = webxr_bridge.create_layer_manager(self);
418+
let device = self
419+
.device_map
420+
.iter()
421+
.next()
422+
.expect("No devices registered with WebGL thread")
423+
.1
424+
.clone();
425+
let result = webxr_bridge.create_layer_manager(&device, self);
419426
let _ = sender.send(result);
420427
},
421428
WebXRCommand::DestroyLayerManager(manager_id) => {

components/webgl/webxr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ impl WebXRBridge {
4747
impl WebXRBridge {
4848
pub(crate) fn create_layer_manager(
4949
&mut self,
50+
device: &Rc<Device>,
5051
contexts: &mut dyn WebXRContexts<WebXRSurfman>,
5152
) -> Result<WebXRLayerManagerId, WebXRError> {
5253
let factory = self
5354
.factory_receiver
5455
.recv()
5556
.map_err(|_| WebXRError::CommunicationError)?;
56-
let manager = factory.build(contexts)?;
57+
let manager = factory.build(device, contexts)?;
5758
let manager_id = WebXRLayerManagerId::new(self.next_manager_id);
5859
self.next_manager_id = self
5960
.next_manager_id

components/webxr/glwindow/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,9 @@ impl GlWindowDevice {
465465
}
466466
let swap_chains = self.swap_chains.clone();
467467
let viewports = self.viewports();
468-
let layer_manager = self
469-
.grand_manager
470-
.create_layer_manager(move |_| Ok(SurfmanLayerManager::new(viewports, swap_chains)))?;
468+
let layer_manager = self.grand_manager.create_layer_manager(move |_, _| {
469+
Ok(SurfmanLayerManager::new(viewports, swap_chains))
470+
})?;
471471
self.layer_manager = Some(layer_manager);
472472
Ok(self.layer_manager.as_mut().unwrap())
473473
}

components/webxr/headless/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ impl HeadlessDevice {
213213
}
214214
let swap_chains = SwapChains::new();
215215
let viewports = self.viewports();
216-
let layer_manager = self
217-
.grand_manager
218-
.create_layer_manager(move |_| Ok(SurfmanLayerManager::new(viewports, swap_chains)))?;
216+
let layer_manager = self.grand_manager.create_layer_manager(move |_, _| {
217+
Ok(SurfmanLayerManager::new(viewports, swap_chains))
218+
})?;
219219
self.layer_manager = Some(layer_manager);
220220
Ok(self.layer_manager.as_mut().unwrap())
221221
}

components/webxr/openxr/graphics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub trait GraphicsProviderMethods<G: Graphics> {
1515
fn enable_graphics_extensions(exts: &mut ExtensionSet);
1616
fn pick_format(formats: &[u32]) -> u32;
1717
fn create_session(
18+
device: &SurfmanDevice,
1819
instance: &Instance,
1920
system: SystemId,
2021
) -> Result<(Session<G>, FrameWaiter, FrameStream<G>), Error>;

components/webxr/openxr/graphics_d3d11.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use openxr::{
1111
ExtensionSet, FormFactor, FrameStream, FrameWaiter, Graphics, Instance, Session, SystemId,
1212
};
1313
use surfman::{
14-
Adapter as SurfmanAdapter, Connection as SurfmanConnection, Context as SurfmanContext,
15-
Device as SurfmanDevice, Error as SurfmanError, SurfaceTexture,
14+
Adapter as SurfmanAdapter, Context as SurfmanContext, Device as SurfmanDevice,
15+
Error as SurfmanError, SurfaceTexture,
1616
};
1717
use webxr_api::Error;
1818
use winapi::Interface;
@@ -50,20 +50,23 @@ impl GraphicsProviderMethods<D3D11> for GraphicsProvider {
5050
}
5151

5252
fn create_session(
53+
device: &SurfmanDevice,
5354
instance: &Instance,
5455
system: SystemId,
5556
) -> Result<(Session<D3D11>, FrameWaiter, FrameStream<D3D11>), Error> {
56-
// FIXME: We should ensure that the OpenXR runtime's texture will be shareable with
57-
// surfman's surfaces by validating the requirements of the XR runtime and ensuring that
58-
// the WebGL context can use the same device when `makeXRCompatible` is called.
59-
let adapter = create_surfman_adapter(instance).ok_or(Error::NoMatchingDevice)?;
60-
let connection = SurfmanConnection::new().map_err(|_| Error::NoMatchingDevice)?;
61-
let device = connection
62-
.create_device(&adapter)
63-
.map_err(|_| Error::NoMatchingDevice)?;
57+
// Get the current surfman device and extract its D3D device. This will ensure
58+
// that the OpenXR runtime's texture will be shareable with surfman's surfaces.
6459
let native_device = device.native_device();
6560
let d3d_device = native_device.d3d11_device;
6661

62+
// FIXME: we should be using these graphics requirements to drive the actual
63+
// d3d device creation, rather than assuming the device that surfman
64+
// already created is appropriate. OpenXR returns a validation error
65+
// unless we call this method, so we call it and ignore the results
66+
// in the short term.
67+
let _requirements = D3D11::requirements(instance, system)
68+
.map_err(|e| Error::BackendSpecific(format!("D3D11::requirements {:?}", e)))?;
69+
6770
unsafe {
6871
instance
6972
.create_session::<D3D11>(

components/webxr/openxr/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,9 +840,9 @@ impl OpenXrDevice {
840840
let shared_data_clone = shared_data.clone();
841841
let mut data = shared_data.lock().unwrap();
842842

843-
let layer_manager = grand_manager.create_layer_manager(move |_| {
843+
let layer_manager = grand_manager.create_layer_manager(move |device, _| {
844844
let (session, frame_waiter, frame_stream) =
845-
GraphicsProvider::create_session(&instance_clone, system)?;
845+
GraphicsProvider::create_session(&*device, &instance_clone, system)?;
846846
let (passthrough, passthrough_layer) = if supports_passthrough {
847847
let flags = PassthroughFlagsFB::IS_RUNNING_AT_CREATION;
848848
let purpose = PassthroughLayerPurposeFB::RECONSTRUCTION;

0 commit comments

Comments
 (0)