Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: a5033751bee41658f6fcddf4b75ede5c0568799d
      
https://github.com/WebKit/WebKit/commit/a5033751bee41658f6fcddf4b75ede5c0568799d
  Author: Sergio Villar Senin <[email protected]>
  Date:   2026-06-03 (Wed, 03 Jun 2026)

  Changed paths:
    M Source/WebCore/Modules/webxr/WebXRWebGLSwapchain.cpp
    M Source/WebCore/Modules/webxr/WebXRWebGLSwapchain.h
    M Source/WebCore/Modules/webxr/XRCompositionLayer.cpp
    M Source/WebCore/Modules/webxr/XRLayerBacking.h
    M Source/WebCore/Modules/webxr/XRWebGLBinding.cpp
    M Source/WebCore/Modules/webxr/XRWebGLLayerBacking.cpp
    M Source/WebCore/Modules/webxr/XRWebGLLayerBacking.h
    M Source/WebCore/html/canvas/WebGLRenderingContextBase.h
    M Source/WebCore/html/canvas/WebGLUtilities.h

  Log Message:
  -----------
  [WebXR Layers] Lots of flickering
rendering
https://flagged.apple.com:443/proxy?t2=dA2j6A5Oy8&o=aHR0cHM6Ly90aHJlZWpzLm9yZy9leGFtcGxlcy8/cT1sYXllcnMjd2ViZ3B1X3hyX25hdGl2ZV9sYXllcnM=&emid=ed880ed6-6ce5-4437-accd-51ef34851ab1&c=11
https://bugs.webkit.org/show_bug.cgi?id=316080

Reviewed by Dan Glastonbury.

The XRCompositionLayer's needsRedraw attribute signals that the layer
should be rendered in the next animation frame. However we were
incorrectly using it in the code to avoid calling startFrame/endFrame.
Because of that the swapchain was not properly cycling between the
buffers/textures provided by the device (OpenXR in this case) causing a
lot of flickering as we were skipping many frames.

The needsRedraw flag should be used by the app to avoid unnecessary draw
commands (for layers whose contents barely change) and not by the engine
as we must keep submitting frames to the XR compositor.

Removing that gating exposed a latent bug in the way we clear the
textures. When clearOnAccess is set the spec
requires
each texture to be
cleared at the moment the application accesses it. We were instead
clearing inside the swapchain's startFrame(), which only appeared
correct because startFrame() was itself gated behind needsRedraw(). It
ran once per frame, on exactly the frames the application was going to
redraw, so the clear happened to line up with the access by coincidence
rather than by design. Once startFrame() runs unconditionally on every
frame (as explained in previous paragraphs) that coincidence no longer
holds; clearing there happens at frame start, before and independently
of the application actually accessing the texture, which is the wrong
place to do it.

The solution is to clear at the real access point. getSubImage()/
getViewSubImage() are exactly where the spec makes the texture available
to the application, so the clear was moved there. Apart from that,
the clear is additionally constrained (via the scissor box) to the subImage's
viewport (for texture
arrays it's
its slice) so that when a single
texture is shared by both eyes, clearing one eye's region on access does
not wipe the other eye's already-rendered content.

* Source/WebCore/Modules/webxr/WebXRWebGLSwapchain.cpp:
(WebCore::WebXRWebGLSwapchain::clearAttachmentRegion):
(WebCore::WebXRWebGLSwapchain::clearTextureRegion):
(WebCore::WebXRWebGLSwapchain::clearTextureIfNeeded):
(WebCore::WebXRWebGLSharedImageSwapchain::startFrame):
(WebCore::WebXRWebGLStaticImageSwapchain::clearTextureRegion):
(WebCore::WebXRWebGLStaticImageSwapchain::startFrame):
(WebCore::WebXRWebGLTextureArraySwapchain::clearTextureRegion):
(WebCore::WebXRWebGLTextureArraySwapchain::startFrame):
(WebCore::WebXRWebGLSwapchain::clearTextureLayers): Deleted.
(WebCore::WebXRWebGLSwapchain::clearCurrentTexture): Deleted.
(WebCore::WebXRWebGLStaticImageSwapchain::clearCurrentTexture): Deleted.
(WebCore::WebXRWebGLTextureArraySwapchain::clearCurrentTexture):
Deleted.
*
Source/WebCore/Modules/webxr/WebXRWebGLSwapchain.h:
* Source/WebCore/Modules/webxr/XRCompositionLayer.cpp:
(WebCore::XRCompositionLayer::startFrame):
(WebCore::XRCompositionLayer::endFrame):
* Source/WebCore/Modules/webxr/XRLayerBacking.h:
(WebCore::XRLayerBacking::clearTexturesIfNeeded):
* Source/WebCore/Modules/webxr/XRWebGLBinding.cpp:
(WebCore::XRWebGLBinding::getSubImage):
(WebCore::XRWebGLBinding::getViewSubImage):
* Source/WebCore/Modules/webxr/XRWebGLLayerBacking.cpp:
(WebCore::XRWebGLLayerBacking::clearTexturesIfNeeded):
* Source/WebCore/Modules/webxr/XRWebGLLayerBacking.h:
* Source/WebCore/html/canvas/WebGLRenderingContextBase.h:
* Source/WebCore/html/canvas/WebGLUtilities.h:
(WebCore::ScopedScissorTestForRegion::ScopedScissorTestForRegion):
(WebCore::ScopedScissorTestForRegion::~ScopedScissorTestForRegion):

Canonical link:
https://flagged.apple.com:443/proxy?t2=DT4d0x9sP9&o=aHR0cHM6Ly9jb21taXRzLndlYmtpdC5vcmcvMzE0NDQxQG1haW4=&emid=ed880ed6-6ce5-4437-accd-51ef34851ab1&c=11



To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to