[webkit-changes] [WebKit/WebKit] 32a1e9: [WebXR] Avoid re-allocation of metal textures for ...

Ada Chan noreply at github.com
Thu May 30 09:50:25 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 32a1e991f51741f6d02c5025fd3773ffcd9302c6
      https://github.com/WebKit/WebKit/commit/32a1e991f51741f6d02c5025fd3773ffcd9302c6
  Author: Ada Chan <adachan at apple.com>
  Date:   2024-05-30 (Thu, 30 May 2024)

  Changed paths:
    M Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.h
    M Source/WebCore/Modules/webxr/WebXROpaqueFramebufferCocoa.cpp
    M Source/WebCore/Modules/webxr/WebXRSession.cpp
    M Source/WebCore/Modules/webxr/WebXRWebGLLayer.cpp
    M Source/WebCore/Modules/webxr/WebXRWebGLLayer.h
    M Source/WebCore/platform/xr/PlatformXR.h
    M Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp
    M Source/WebCore/testing/WebFakeXRDevice.cpp
    M Source/WebKit/Shared/XR/PlatformXR.serialization.in
    M Source/WebKit/UIProcess/XR/ios/PlatformXRARKit.mm

  Log Message:
  -----------
  [WebXR] Avoid re-allocation of metal textures for every frame
https://bugs.webkit.org/show_bug.cgi?id=274882
rdar://128010992

Reviewed by Dan Glastonbury and Mike Wyrzykowski.

Before this code change, metal texture handles are passed in
the frame data for every frame render, and we'd allocate a metal
texture from this handle (and later deallocate it) for each frame.

With this change, we allow textures to be reused. PlatformXRSystem
can send back a reusable index along with the texture handle, and
WebXROpaqueFramebuffer caches the allocated texture with that index.
When this same texture can be reused in a future frame, PlatformXRSystem
will send back that index in the frame data with a null texture handle
as a signal that the last texture stored at that index should be used.

* Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.h:
(WebCore::WebXRExternalRenderbuffer::operator bool const):
(WebCore::WebXRAttachmentSet::operator bool const):
* Source/WebCore/Modules/webxr/WebXROpaqueFramebufferCocoa.cpp:
(WebCore::WebXROpaqueFramebuffer::~WebXROpaqueFramebuffer):
The cleanup of the display attachments is now handled in releaseAllDisplayAttachments().
(WebCore::WebXROpaqueFramebuffer::startFrame):
Call the new helper method bindCompositorTexturesForDisplay() that will
reuse a cached texture if possible.
(WebCore::WebXROpaqueFramebuffer::endFrame):
We no longer need to deallocate the texture after each frame render.
(WebCore::WebXROpaqueFramebuffer::releaseAllDisplayAttachments):
Release all the cached display attachments.
(WebCore::WebXROpaqueFramebuffer::blitShared):
(WebCore::WebXROpaqueFramebuffer::blitSharedToLayered):
(WebCore::WebXROpaqueFramebuffer::reusableDisplayAttachments const):
If texture handle is null, return the texture cached at the reusableTextureIndex.
(WebCore::WebXROpaqueFramebuffer::bindCompositorTexturesForDisplay):
First, ensure the m_displayAttachmentsSets vector is large enough to store
the set of display attachments used for this frame render. If there's no
layerData.textureData, which is the case when we run layout tests, create a
temporary renderbuffer to be used as the display color buffer. Otherwise,
check if we can reuse a previously created texture. If reuse is not possible,
create new textures with the handles passed in the frame data.
(WebCore::WebXROpaqueFramebuffer::releaseDisplayAttachmentsAtIndex):
Helper method to clean up the display attachments, refactored from old code.
* Source/WebCore/Modules/webxr/WebXRSession.cpp:
(WebCore::WebXRSession::didCompleteShutdown):
* Source/WebCore/Modules/webxr/WebXRWebGLLayer.cpp:
(WebCore::WebXRWebGLLayer::sessionEnded):
Clean up any cached display attachments.
* Source/WebCore/Modules/webxr/WebXRWebGLLayer.h:
* Source/WebCore/platform/xr/PlatformXR.h:
Introduce ExternalTextureData that packages up all the texture info
along with the reusable index.
Store LayerData with UniqueRef so we don't have to worry about its
size getting too large to be hashable.
* Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp:
(PlatformXR::OpenXRDevice::requestFrame):
* Source/WebCore/testing/WebFakeXRDevice.cpp:
(WebCore::SimulatedXRDevice::frameTimerFired):
Don't pass any textureData from the fake device so a temporary
renderbuffer will be used for the color display buffer.
* Source/WebKit/Shared/XR/PlatformXR.serialization.in:
* Source/WebKit/UIProcess/XR/ios/PlatformXRARKit.mm:
(WebKit::ARKitCoordinator::renderLoop):

Canonical link: https://commits.webkit.org/279523@main



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


More information about the webkit-changes mailing list