feat: WebGPU XR device loss, devicelost events, and graphics binding typings#8719
Merged
Conversation
…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.
Contributor
There was a problem hiding this comment.
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/devicerestoredevent 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
graphicsBindingto 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
getFramebufferSizereadslayer.width/layer.height, but_layeris now typed asXRProjectionLayer|null. Even if WebXR runtime objects sometimes expose these fields, the WebXR Layers typings forXRProjectionLayertypically only definetextureWidth/textureHeight, so this change is likely to breakcheckJstype-checking. Consider restoring theanycast 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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Improves WebGPU immersive XR behavior when the GPU device is lost and restored, aligns
devicelost/devicerestoredwith the WebGL path, and tightens typings documentation forgraphicsBindingwithout requiring WebGPU type packages.Changes:
WebgpuXrBridgeclears binding, layer, XR color texture state, and sessionlayerson device loss; re-attaches presentation after restore (aligned with WebGL XR bridge behavior).handleDeviceLostnow firesdevicelostafterloseContextanddevicerestoredafterrestoreContext, so listeners (e.g.XrBridge) run on WebGPU as well.devicelost/devicerestoredfire at the end ofWebglGraphicsDevicelose/restore (after shader teardown); context lost/restored handlers only callloseContext/restoreContext.GraphicsDevicelogs backend-neutral messages at the start ofloseContext/restoreContextso WebGL and WebGPU both log the same lines in debug builds.XrManager#graphicsBindingandXrBridge#graphicsBindingare documented asObject | nullwith WebGL / WebGPU binding notes instead of WebGL-onlyXRWebGLBinding.API changes:
XrManager.prototype.graphicsBindingandXrBridge.prototype.graphicsBindingnow resolve asany | null(fromObject | nullin JSDoc) rather thanXRWebGLBinding | null, reflecting that the value may be a WebGPU binding when using WebGPU XR.