Skip to content

[Epic] WebGPU support for WebXR #18635

Description

@RaananW

Summary

WebXR in Babylon.js is currently tightly coupled to WebGL2. This epic tracks a phased effort to decouple the WebXR subsystem from the WebGL rendering backend and add support for WebGPU-backed XR sessions via the immersive-web WebXR‑WebGPU‑Binding spec (XRGPUBinding), now available experimentally in the Meta Quest Browser.

Motivation

  • WebGPU offers significantly better rendering performance for demanding XR workloads.
  • The Quest Browser now exposes an experimental XRGPUBinding implementation.
  • Babylon's WebGPU engine already provides the core primitive we need: AbstractEngine.wrapWebGPUTexture(GPUTexture): InternalTexture.

Key spec constraints

  • A WebGPU XR session is requested via the 'webgpu' feature descriptor and requires an xrCompatible: true adapter.
  • In a WebGPU session, XRWebGLLayer / XRWebGLBinding cannot be created and updateRenderState({ baseLayer }) is disallowed — rendering must go through the layers path (XRProjectionLayer). This makes the WebXR Layers path mandatory rather than optional.
  • Per-frame rendering uses XRGPUBinding.getViewSubImage(layer, view) / getSubImage(...), returning XRGPUSubImage objects that expose GPUTexture color/depth attachments plus a GPUTextureViewDescriptor and viewport.
  • WebGPU XR views return projection matrices with a [0, 1] clip-space depth range (vs [-1, 1] for WebGL).

Approach & decisions

  • Full feature parity is the end goal (projection + composition/quad layers + binding-based features).
  • Phase 0 ships first as an independent, behavior-preserving WebGL-only refactor that de-risks everything after it.
  • Graceful degradation: features without a WebGPU-XR equivalent disable themselves with a console warning rather than throwing.
  • Testing: devHost testScene + manual Meta Quest Browser verification, backed by non-XR WebGPU unit/visualization regression.

Phases (tracked as sub-issues)

  • Phase 0 — Foundation: make the WebXR layer / render-target abstraction API-agnostic
  • Phase 1 — WebGPU-compatible XR session + XRGPUBinding plumbing
  • Phase 2 — WebGPU projection layer + render target provider
  • Phase 3 — WebXR camera projection matrix / NDC handling for WebGPU
  • Phase 4 — Feature parity (composition/quad layers + binding-based features)
  • Phase 5 — Testing, graceful fallback, and documentation

Each phase is tracked as a sub-issue below; individual PRs will reference the relevant phase sub-issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions