Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new WebXR API in script #23731

Merged
merged 19 commits into from Jul 12, 2019
Merged

Use new WebXR API in script #23731

merged 19 commits into from Jul 12, 2019

Conversation

@Manishearth
Copy link
Member

Manishearth commented Jul 8, 2019

Todo:

  • Hook new Frame information into XRFrame
  • Make spaces use new transform info
  • Hook up session view metadata correctly
  • Get mocking working again
  • Get inputs working

Optional todos:

  • Add support for active and animationFrame bool on XRFrame
  • Correctly handle viewer and offset spaces instead of casting
  • Error on zero-length quaternions

Not really ready for review yet, but you can go ahead and review what I have so far. It doesn't do anything yet, aside from crash horribly. I'm opening this PR early so i have a place to track progress.


This change is Reviewable

@Manishearth Manishearth requested a review from asajeffrey Jul 8, 2019
@highfive
Copy link

highfive commented Jul 8, 2019

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/xrrenderstate.rs, components/script/dom/webidls/XRSession.webidl, components/script/Cargo.toml, components/script/dom/xrview.rs, components/script/dom/bindings/trace.rs and 5 more
  • @KiChjang: components/script/dom/xrrenderstate.rs, components/script/dom/webidls/XRSession.webidl, components/script/Cargo.toml, components/script/dom/xrview.rs, components/script/dom/bindings/trace.rs and 5 more
@highfive
Copy link

highfive commented Jul 8, 2019

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@Manishearth Manishearth force-pushed the Manishearth:webxr-script branch 9 times, most recently from 2dd8c3e to 59c8d85 Jul 9, 2019
@Manishearth
Copy link
Member Author

Manishearth commented Jul 9, 2019

Can start reviewing now

@Manishearth Manishearth force-pushed the Manishearth:webxr-script branch from 59c8d85 to 65180a5 Jul 9, 2019
Copy link
Member

asajeffrey left a comment

OK, this looks good so far. There are a few sources of panic that we should probably get rid of before merging, and there's an annoying extra thread kept alive because script doesn't support serializable tasks. I see what you mean about the typed transforms, the types are just getting in the way because by the time the transforms get to JS they're untyped.

components/script/dom/bindings/trace.rs Show resolved Hide resolved
components/script/dom/xr.rs Show resolved Hide resolved
components/script/dom/xr.rs Show resolved Hide resolved
components/script/dom/xr.rs Outdated Show resolved Hide resolved
components/script/dom/xr.rs Outdated Show resolved Hide resolved

#[allow(unsafe_code)]
pub fn cast_transform<T, U, V, W>(transform: TypedRigidTransform3D<f32, T, U>) -> TypedRigidTransform3D<f32, V, W> {
unsafe { mem::transmute(transform) }

This comment has been minimized.

Copy link
@asajeffrey

asajeffrey Jul 9, 2019

Member

We can make this safe by casting to and from an untyped transform?

This comment has been minimized.

Copy link
@Manishearth

Manishearth Jul 9, 2019

Author Member

There's no cast function.

This comment has been minimized.

Copy link
@asajeffrey

asajeffrey Jul 9, 2019

Member

Er, to_untyped() and from_untyped()?

This comment has been minimized.

Copy link
@asajeffrey

asajeffrey Jul 9, 2019

Member

Ah, those are only on TypedTransform not TypedRigidTransform?

// XXXManishearth handle inline sessions and composition disabled flag
let layer = pending.GetBaseLayer();
if let Some(layer) = layer {
let layer = layer.downcast::<XRWebGLLayer>().unwrap();

This comment has been minimized.

Copy link
@asajeffrey

asajeffrey Jul 9, 2019

Member

Handle the case of a non-XRWebGLLayer without panicking?

.dom_manipulation_task_source_with_canceller();
let (sender, receiver) = ipc::channel(global.time_profiler_chan().clone()).unwrap();
*self.raf_sender.borrow_mut() = Some(sender);
ROUTER.add_route(

This comment has been minimized.

Copy link
@asajeffrey

asajeffrey Jul 9, 2019

Member

Ouch, we're using a ROUTER, which means a context switch every frame.

This comment has been minimized.

Copy link
@asajeffrey

asajeffrey Jul 9, 2019

Member

We can discuss this in #23733.

This comment has been minimized.

Copy link
@gterzian

gterzian Jul 10, 2019

Member

Ok so, if the goal is really removing the router from the equation for this specific workflow, here's an idea for your consideration:

At this very line, instead of using the ROUTER, queue a task that does the below:

  1. let frame = raf_receiver.recv(); (or return if you're inactive)
  2. self.raf_callback(frame);
  3. If !self.raf_callback_list.is_empty()
  4. request_animation_frame
  5. queue a task to start at 1
  6. Or, if there are no callbacks or the session has ended, skip 4 and 5

If you don't need to actually run tasks, or handle messages from the constellation, you could try an even more drastic approach where instead of running one callback in one task, you'd keep requesting frames and running callbacks for as long as new callbacks are added inside a callback, and for as long as the session remains active(and the pipeline isn't closed?). And that from within the same task, effectively blocking the script-thread in the meantime(but running the callbacks as "fast" as possible, I guess).

So you could just queue a task in the first requestAnimationFrame call, and after that just loop inside the same task, running a mini-event-loop inside the otherwise blocked window event-loop...

This comment has been minimized.

Copy link
@asajeffrey

asajeffrey Jul 10, 2019

Member

We could do something like that, but this would mean blocking the script thread while waiting for the raf_receiver.recv(), and IPC channels don't support recv_timeout(). Sigh. I think this would need quite a drastic re-think of how Servo approaches IPC.

@Manishearth
Copy link
Member Author

Manishearth commented Jul 9, 2019

Addressed.

@Manishearth Manishearth force-pushed the Manishearth:webxr-script branch from d3a98f7 to 390a482 Jul 9, 2019
@Manishearth
Copy link
Member Author

Manishearth commented Jul 9, 2019

There are no untyped functions on half the euclid types

https://docs.rs/euclid/0.19.7/euclid/struct.TypedRigidTransform3D.html

@Manishearth
Copy link
Member Author

Manishearth commented Jul 10, 2019

Mocking works! I'll still need to fix the test again

@Manishearth Manishearth force-pushed the Manishearth:webxr-script branch from 7353275 to afafc17 Jul 10, 2019
@Manishearth
Copy link
Member Author

Manishearth commented Jul 10, 2019

input's done, as well. ready for review.

I haven't yet tested locally (can't test on my laptop), will do after this meeting

@Manishearth Manishearth force-pushed the Manishearth:webxr-script branch from 74e3d9e to 9d5252b Jul 10, 2019
@asajeffrey
Copy link
Member

asajeffrey commented Jul 10, 2019

Argh, did you know github gets very confused if you force-push while there's a review being written?

Copy link
Member

asajeffrey left a comment

Yay, looks pretty good. Usual collection of nip-picks and bikesheds.

components/script/dom/fakexrdevice.rs Show resolved Hide resolved
}

pub fn get_views(views: &[FakeXRViewInit]) -> Fallible<(MockVRView, MockVRView)> {
pub fn get_views(views: &[FakeXRViewInit]) -> Fallible<Views> {
if views.len() != 2 {
return Err(Error::NotSupported);

This comment has been minimized.

Copy link
@asajeffrey

asajeffrey Jul 10, 2019

Member

Might want to support mono at some point.

This comment has been minimized.

Copy link
@Manishearth

Manishearth Jul 11, 2019

Author Member

Yeah, inline support needs a bit more work

components/script/dom/webidls/XRTest.webidl Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
components/script/dom/fakexrdevice.rs Show resolved Hide resolved
components/script/dom/fakexrdevice.rs Outdated Show resolved Hide resolved
components/script/dom/fakexrdevice.rs Outdated Show resolved Hide resolved
components/script/dom/xrrenderstate.rs Outdated Show resolved Hide resolved
@Manishearth Manishearth force-pushed the Manishearth:webxr-script branch from 9d5252b to 70688bc Jul 10, 2019
@Manishearth Manishearth force-pushed the Manishearth:webxr-script branch from b897b30 to c5a0fc5 Jul 11, 2019
@asajeffrey
Copy link
Member

asajeffrey commented Jul 11, 2019

The failure with glwindow is probably OK, but we should fix the mock API. In particular, mirroring isn't working, possibly because we're not marking the canvas as dirty after an XR rAF?

@Manishearth
Copy link
Member Author

Manishearth commented Jul 11, 2019

The tests still work, which makes me kinda okay with the mock API being broken.

@asajeffrey
Copy link
Member

asajeffrey commented Jul 11, 2019

Yes, I think it's display mirroring that's broken. I think it's OK to merge with that. You can r=me.

Can we enable some webxr tests now?

@Manishearth
Copy link
Member Author

Manishearth commented Jul 11, 2019

@bors-servo r=asajeffrey

not yet, Chrome is still fixing them

@bors-servo
Copy link
Contributor

bors-servo commented Jul 11, 2019

📌 Commit c5a0fc5 has been approved by asajeffrey

@bors-servo
Copy link
Contributor

bors-servo commented Jul 11, 2019

Testing commit c5a0fc5 with merge 5fdc7c0...

bors-servo added a commit that referenced this pull request Jul 11, 2019
Use new WebXR API in script

Todo:
 - [x] Hook new `Frame` information into `XRFrame`
 - [x] Make spaces use new transform info
 - [x] Hook up session view metadata correctly
 - [x] Get mocking working again
 - [x] Get inputs working

Optional todos:
 - [x] Add support for active and animationFrame bool on XRFrame
 - [x] Correctly handle viewer and offset spaces instead of casting
 - [x] Error on zero-length quaternions

<s>Not really ready for review yet, but you can go ahead and review what I have so far. It doesn't do anything yet, aside from crash horribly. I'm opening this PR early so i have a place to track progress.</s>

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23731)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 12, 2019

☀️ Test successful - linux-rel-css, linux-rel-wpt, status-taskcluster
Approved by: asajeffrey
Pushing 5fdc7c0 to master...

@bors-servo bors-servo merged commit c5a0fc5 into servo:master Jul 12, 2019
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
Taskcluster (pull_request) TaskGroup: success
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.