Skip to content

fix(graphics): align WebGPU backbuffer format with WebXR projection-layer format#8914

Merged
mvaligursky merged 2 commits into
mainfrom
mv-webgpu-xr-backbuffer-format
Jun 16, 2026
Merged

fix(graphics): align WebGPU backbuffer format with WebXR projection-layer format#8914
mvaligursky merged 2 commits into
mainfrom
mv-webgpu-xr-backbuffer-format

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

While in an immersive WebGPU XR session, the engine-level backbuffer format (device.backBufferFormat) stayed pinned to the canvas swapchain format chosen at startup, even though XR renders into the WebXR projection layer — whose format the runtime recommends independently via XRGPUBinding.getPreferredColorFormat(). Systems that key off backBufferFormat — notably RenderTarget#isColorBufferSrgb, which drives output gamma correction in the forward renderer and compose pass, plus scene color-grab — therefore used the wrong format during XR. This could produce gamma-incorrect XR output (too dark/bright vs the 2D canvas) when the projection layer's sRGB-ness differed from the canvas format.

Changes:

  • WebGPU XR now overrides device.backBufferFormat with the active projection layer's per-eye view format each frame, reverting to the canvas-derived format when the immersive frame/session ends (centralized in _clearXrState, which is hit on every teardown path).
  • The per-eye view format is used (rather than the raw getPreferredColorFormat() string) because it carries the runtime's sRGB reinterpretation, which is what actually determines hardware gamma encoding on write.

No public API changes — all additions are internal (@ignore / private).

…ayer format

While immersive, device.backBufferFormat stayed pinned to the canvas swapchain
format instead of the WebXR projection-layer format the runtime renders into.
Systems keyed off it - RenderTarget#isColorBufferSrgb (forward-renderer / compose
gamma correction) and scene color-grab - used the wrong format, risking
gamma-incorrect XR output. Override it each frame from the projection layer's
per-eye view format (which carries the runtime's sRGB reinterpretation) and revert
on frame/session teardown via _clearXrState.

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 fixes WebGPU immersive WebXR rendering by keeping the engine’s GraphicsDevice#backBufferFormat aligned with the active WebXR projection-layer view format (including the runtime’s sRGB reinterpretation), so format-dependent systems (gamma/output correction and scene color-grab) behave consistently during XR and then revert back to the canvas-derived format on teardown.

Changes:

  • WebGPU XR now updates device.backBufferFormat from the active projection layer’s per-eye viewFormat during beginFrame.
  • WebgpuGraphicsDevice tracks the canvas-derived backbuffer format and restores it in _clearXrState.
  • Added a WebGPU texture-format → engine PIXELFORMAT_* mapping used for the XR override.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/platform/graphics/webgpu/webgpu-xr-bridge.js Sets XR color texture/view format and applies the XR-driven backbuffer format override each frame.
src/platform/graphics/webgpu/webgpu-graphics-device.js Adds format mapping and canvas-format capture/restore to support correct backBufferFormat behavior during/after XR.

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

Comment thread src/platform/graphics/webgpu/webgpu-xr-bridge.js
@mvaligursky mvaligursky merged commit 37770ff into main Jun 16, 2026
9 checks passed
@mvaligursky mvaligursky deleted the mv-webgpu-xr-backbuffer-format branch June 16, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: xr XR related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants