Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Exokit's architecture has up until this point been mostly singlethreaded. This means that the render loop, and all user code animation frames ran in the same thread. This is mostly because that is how
node
(used to) work.However, this is problematic for several reasons:
Node 11+12 have full threading support, which mostly follows the WebWorker API.
This PR leverages
worker_threads
to run all user window code in parallel, separate from the render loop. The architecture is as follows:window
s, corresponding to webwindow
contextswindow
contexts:waitPose
,tickAnimationFrame
,submitFrame
. This is effected by posting messages down childwindow
s, and capturing the response in aPromise
which we can.then
on<iframe>
s which it is composing into its scene, each window is also its own render loop, and proxies the three-phase XR to its child windows. This forms a virtual render tree structure made ofwindow
contextswindow
renders, waited on by its owningwindow
, in order to effect perfect frame synchronization for apps in the ideal casesetTimeout
and continue rendering without it, and do not dispatch any morerequestAnimationFrame
to it -- whenever the app finishes the render and resolves the correspondingPromise
, we will pick up the frame on the next available render loop tick and resume furtherrequestAnimationFrame
to itThough this PR does not do it yet, this opens up the path to full Service Worker and audio thread support, as well as 3D framebuffer reprojection support for applications so that we maintain frame rate even in cases where the user code cannot keep up (due to loading, being badly written, etc).
Most of the changes here are instituting the new render loop request/response, and fixing the places in the code that assumed everything was running synchronously in one thread.
Overall user code should see no change here, other than that everything becomes faster for free, especially -- but not only -- when using reality tabs in XR. 🦄 🌈