Skip to content

feat: WebGPU XR device loss, devicelost events, and graphics binding typings#8719

Merged
mvaligursky merged 3 commits into
mainfrom
mv-webgpu-xr-device-events
May 11, 2026
Merged

feat: WebGPU XR device loss, devicelost events, and graphics binding typings#8719
mvaligursky merged 3 commits into
mainfrom
mv-webgpu-xr-device-events

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

Improves WebGPU immersive XR behavior when the GPU device is lost and restored, aligns devicelost / devicerestored with the WebGL path, and tightens typings documentation for graphicsBinding without requiring WebGPU type packages.

Changes:

  • WebGPU XR: WebgpuXrBridge clears binding, layer, XR color texture state, and session layers on device loss; re-attaches presentation after restore (aligned with WebGL XR bridge behavior).
  • WebGPU graphics: handleDeviceLost now fires devicelost after loseContext and devicerestored after restoreContext, so listeners (e.g. XrBridge) run on WebGPU as well.
  • WebGL graphics: devicelost / devicerestored fire at the end of WebglGraphicsDevice lose/restore (after shader teardown); context lost/restored handlers only call loseContext / restoreContext.
  • Shared: GraphicsDevice logs backend-neutral messages at the start of loseContext / restoreContext so WebGL and WebGPU both log the same lines in debug builds.
  • Types (JSDoc): XrManager#graphicsBinding and XrBridge#graphicsBinding are documented as Object | null with WebGL / WebGPU binding notes instead of WebGL-only XRWebGLBinding.

API changes:

  • Published typings for XrManager.prototype.graphicsBinding and XrBridge.prototype.graphicsBinding now resolve as any | null (from Object | null in JSDoc) rather than XRWebGLBinding | null, reflecting that the value may be a WebGPU binding when using WebGPU XR.

…typings

Implement WebgpuXrBridge GPU lost/restore parity with WebGL, emit devicelost/devicerestored on WebGPU, unify context logs in GraphicsDevice, and defer WebGL devicelost until after shader teardown.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves resilience and consistency of device-loss handling across WebGPU/WebGL, especially for immersive WebXR, and updates XR graphicsBinding typings/docs to reflect backend-specific bindings.

Changes:

  • Align devicelost / devicerestored event ordering between WebGL and WebGPU by firing them at the end of lose/restore flows.
  • Add WebGPU XR device-loss handling to clear XR binding/layer state and re-attach presentation after device restore.
  • Update public JSDoc for graphicsBinding to be backend-agnostic (Object|null) and document WebGL vs WebGPU bindings.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/platform/graphics/xr-bridge.js Updates graphicsBinding getter JSDoc to be backend-agnostic.
src/platform/graphics/webgpu/webgpu-xr-bridge.js Adds XR device lost/restored handling; updates internal JSDoc typing for WebXR WebGPU objects.
src/platform/graphics/webgpu/webgpu-graphics-device.js Fires devicelost / devicerestored around WebGPU device recreation.
src/platform/graphics/webgl/webgl-graphics-device.js Moves devicelost / devicerestored firing into lose/restore methods.
src/platform/graphics/graphics-device.js Adds backend-neutral logging for context lose/restore.
src/framework/xr/xr-manager.js Updates graphicsBinding JSDoc/type to `Object
Comments suppressed due to low confidence (1)

src/platform/graphics/webgpu/webgpu-xr-bridge.js:126

  • getFramebufferSize reads layer.width / layer.height, but _layer is now typed as XRProjectionLayer|null. Even if WebXR runtime objects sometimes expose these fields, the WebXR Layers typings for XRProjectionLayer typically only define textureWidth / textureHeight, so this change is likely to break checkJs type-checking. Consider restoring the any cast here or narrowing the fallback to fields that are actually part of the typed API.
    getFramebufferSize(_frame, out) {
        const layer = this._layer;
        if (layer) {
            const lw = layer.textureWidth ?? layer.width;
            const lh = layer.textureHeight ?? layer.height;
            if (lw > 0 && lh > 0) {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/platform/graphics/webgpu/webgpu-xr-bridge.js
Comment thread src/platform/graphics/webgpu/webgpu-graphics-device.js Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@mvaligursky mvaligursky merged commit c7612f6 into main May 11, 2026
8 checks passed
@mvaligursky mvaligursky deleted the mv-webgpu-xr-device-events branch May 11, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: graphics Graphics related issue area: xr XR related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants