Skip to content

WebXRManager: Set glBinding separately from layer creation. #31443

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

Merged
merged 2 commits into from
Jul 20, 2025

Conversation

mikeskydev
Copy link
Contributor

Related issues: #26891, #30282

Description

I'm working on adding WebXR Camera Access, which requires glBinding to be set for access to the raw images. This is possible independently of WebXR Layers support, so I'm proposing to move the assignment outside of the useLayers guard.

I note that XRWebGLBinding is defined in the WebXR Layers spec, but it works without layers as demonstrated on this example (source).

Copy link

github-actions bot commented Jul 18, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 338.02
78.86
338.04
78.86
+12 B
+1 B
WebGPU 558.57
154.64
558.66
154.66
+96 B
+22 B
WebGPU Nodes 557.49
154.42
557.58
154.45
+96 B
+22 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 469.28
113.56
469.29
113.56
+12 B
+5 B
WebGPU 633.86
171.66
633.95
171.68
+96 B
+17 B
WebGPU Nodes 588.99
160.99
589.09
161.01
+96 B
+20 B

@mikeskydev mikeskydev changed the title [WebXR] Set glBinding separately from layer creation WebXRManager: Set glBinding separately from layer creation Jul 18, 2025
@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 18, 2025

Can you please keep XRManager in sync with WebXRManager?

WebXRManager is the XR manager for WebGLRenderer. XRManager is the XR manager for WebGPURenderer.

https://github.com/mrdoob/three.js/blob/dev/src/renderers/common/XRManager.js

@mikeskydev
Copy link
Contributor Author

Can you please keep XRManager in sync with WebXRManager?

WebXRManager is the XR manager for WebGLRenderer. XRManager is the XR manager for WebGPURenderer.

https://github.com/mrdoob/three.js/blob/dev/src/renderers/common/XRManager.js

I didn't notice that class, but sure thing. But is it basically just falling back to a WebGL implementation right now?

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 18, 2025

WebGPURenderer has a WebGL backend which acts as a fallback if WebGPU isn't available. The respective XR manager does only support WebGL right now since the WebGPU/WebXR API isn't ready yet.

@Mugen87 Mugen87 added this to the r179 milestone Jul 19, 2025
@Mugen87 Mugen87 changed the title WebXRManager: Set glBinding separately from layer creation WebXRManager: Set glBinding separately from layer creation. Jul 19, 2025
@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 19, 2025

/cc @cabanier

@cabanier
Copy link
Contributor

/cc @cabanier

Thanks for the ping! This change looks good to me as the binding does not require layers and afaik this is not a heavy operation. We could potentially improve it with lazy initialization so it's only constructed when needed.

@Mugen87 Mugen87 merged commit 297385a into mrdoob:dev Jul 20, 2025
9 checks passed
@mikeskydev mikeskydev deleted the fix/xrwebglbinding-create branch July 21, 2025 07:44
@harryhjsh
Copy link
Contributor

This has an impact on the Meta Immersive Web Emulator, and anything else using the WebXR Device API polyfill without the WebXR Layers polyfill -- trying to construct the native impl of WebXRGLBinding with the polyfilled XRSession throws.

I don't think this is a problem to be solved here if XRWebGLBinding does not require layers, but just wanted to document it. Currently none of the examples run in XR with the emulator on r179.

@harryhjsh
Copy link
Contributor

harryhjsh commented Aug 14, 2025

Looking further into it I think that this is just a regression on #30319 due to moving the construction outside the useLayers check. Possibly a PR would be acceptable here to do the same safe check before the initial XRWebGLBinding construction? @Mugen87
Also related #31432, meta-quest/immersive-web-emulator#70

@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 14, 2025

I'm not sure I understand. We are still using the typeof XRWebGLBinding !== 'undefined' check from #30319. Just at a different place.

@harryhjsh
Copy link
Contributor

harryhjsh commented Aug 14, 2025

Sorry, I've gotten myself confused. I made an assumption that #30319 added the createProjectionLayer check, which obviously doesn't make sense in the context of this PR.

If you try any of the XR examples on the emulator you'll hopefully see what I mean. I'm not sure that it's something we can solve here anymore though. XRWebGLBinding is defined when not polyfilled, but a polyfilled XRSession can't be used to create it. If we need to construct it even without layers support, solving the emulator issue here would mean specifically checking whether the XRSession is valid/not polyfilled before construction, which doesn't seem desirable. It seems likely that this probably has to be a downstream issue now.

@harryhjsh
Copy link
Contributor

harryhjsh commented Aug 14, 2025

On (continued) further reflection, I think that implementing @cabanier's suggestion to lazily initialise the XRWebGLBinding is probably worth doing to go towards solving the above discussion. It would mean that session.enabledFeatures can decide when/whether XRWebGLBinding is constructed. Do you think a PR for that change would be acceptable, @Mugen87?

@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 14, 2025

If that fixes the issue with the emulator, I would say yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants