[webkit-changes] [WebKit/WebKit] b54dc9: [WebGPU] Move prepareForDisplay() from Presentatio...

Myles C. Maxfield noreply at github.com
Thu Feb 2 13:48:51 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: b54dc9debcec25e8e59b943c5e1afc863e181477
      https://github.com/WebKit/WebKit/commit/b54dc9debcec25e8e59b943c5e1afc863e181477
  Author: Myles C. Maxfield <mmaxfield at apple.com>
  Date:   2023-02-02 (Thu, 02 Feb 2023)

  Changed paths:
    M Source/WebCore/Modules/WebGPU/GPUCompositorIntegration.cpp
    M Source/WebCore/Modules/WebGPU/GPUCompositorIntegration.h
    R Source/WebCore/Modules/WebGPU/GPUPresentationConfiguration.h
    M Source/WebCore/Modules/WebGPU/GPUPresentationContext.cpp
    M Source/WebCore/Modules/WebGPU/GPUPresentationContext.h
    M Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj
    M Source/WebCore/PAL/pal/CMakeLists.txt
    M Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUCompositorIntegrationImpl.cpp
    M Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUCompositorIntegrationImpl.h
    M Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUConvertToBackingContext.h
    M Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUImpl.cpp
    M Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUPresentationContextImpl.cpp
    M Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUPresentationContextImpl.h
    M Source/WebCore/PAL/pal/graphics/WebGPU/WebGPUCompositorIntegration.h
    R Source/WebCore/PAL/pal/graphics/WebGPU/WebGPUPresentationConfiguration.h
    M Source/WebCore/PAL/pal/graphics/WebGPU/WebGPUPresentationContext.h
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/html/canvas/GPUCanvasContextCocoa.cpp
    M Source/WebCore/html/canvas/GPUCanvasContextCocoa.h
    M Source/WebGPU/WebGPU/PresentationContext.h
    M Source/WebGPU/WebGPU/PresentationContext.mm
    M Source/WebGPU/WebGPU/PresentationContextCoreAnimation.h
    M Source/WebGPU/WebGPU/PresentationContextCoreAnimation.mm
    M Source/WebGPU/WebGPU/PresentationContextIOSurface.h
    M Source/WebGPU/WebGPU/PresentationContextIOSurface.mm
    M Source/WebGPU/WebGPU/Texture.h
    M Source/WebGPU/WebGPU/Texture.mm
    M Source/WebGPU/WebGPU/WebGPUExt.h
    M Source/WebKit/CMakeLists.txt
    M Source/WebKit/DerivedSources.make
    M Source/WebKit/GPUProcess/graphics/WebGPU/RemoteCompositorIntegration.cpp
    M Source/WebKit/GPUProcess/graphics/WebGPU/RemoteCompositorIntegration.h
    M Source/WebKit/GPUProcess/graphics/WebGPU/RemoteCompositorIntegration.messages.in
    M Source/WebKit/GPUProcess/graphics/WebGPU/RemotePresentationContext.cpp
    M Source/WebKit/GPUProcess/graphics/WebGPU/RemotePresentationContext.h
    M Source/WebKit/GPUProcess/graphics/WebGPU/RemotePresentationContext.messages.in
    M Source/WebKit/Scripts/webkit/messages.py
    M Source/WebKit/Shared/WebGPU/WebGPUConvertFromBackingContext.h
    M Source/WebKit/Shared/WebGPU/WebGPUConvertToBackingContext.h
    R Source/WebKit/Shared/WebGPU/WebGPUPresentationConfiguration.cpp
    R Source/WebKit/Shared/WebGPU/WebGPUPresentationConfiguration.h
    R Source/WebKit/Shared/WebGPU/WebGPUPresentationConfiguration.serialization.in
    M Source/WebKit/Sources.txt
    M Source/WebKit/WebKit.xcodeproj/project.pbxproj
    M Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteCompositorIntegrationProxy.cpp
    M Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteCompositorIntegrationProxy.h
    M Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemotePresentationContextProxy.cpp
    M Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemotePresentationContextProxy.h

  Log Message:
  -----------
  [WebGPU] Move prepareForDisplay() from PresentationContext to CompositorIntegration
https://bugs.webkit.org/show_bug.cgi?id=251564
rdar://104942364

Reviewed by Dean Jackson.

This patch starts the data flow for WebGPU compositing that I've been working toward. Recall that we
have 2 related objects: 1) CompositorIntegration, which is our own object that has no WebGPU equivalent,
that we can use to add any methods we want, and 2) PresentationContext, which represents a
GPUCanvasContext (and a WGPUSurface/WGPUSwapChain pair).

In the new flow, whenever the canvas context is reconfigured, we synchronously tell the GPU process and
receive new IOSurfaces. This way, we don't have to send an IOSurface each frame, because the web process
already has all the IOSurfaces in the swap chain.

When creating a CompositorIntegration/PresentationContext pair, we do a handshake between them so
CompositorIntegration can call into PresentationContext and into the WGPUPresentationContext. This
handshake involves some blocks that get passed around, so these objects can call each others' methods
without adding new API to the classes. The ownership model is that the CompositorIntegrationImpl
contains a strong ref to the PresentationContextImpl, and a strong ref to the WGPUPresentationContext
via the capture scope of a block it owns. I think this is the right ownership model: the
CompositorIntegration is conceptually a higher-level object than the PresentationContext, so a ref from
CompositorIntegration to PresentationContext seems like the right direction.

GPUCanvasContextCocoa::configure():
1. Calls CompositorIntegration::recreateRenderBuffers(). This synchronously recreates the IOSurfaces.
Not only does CompositorIntegration::recreateRenderBuffers() synchronously recreate the IOSurfaces, but
it also notifies the PresentationContext that new IOSurfaces were created. The PresentationContext
remembers the IOSurfaces, because...
2. GPUCanvasContextCocoa::configure() then calls PresentationContext::configure(). This is where all the
details of the texture objects get passed in. At this point, PresentationContext creates internal
textures wrapping each of the IOSurfaces, and retains them.

Because we eagerly create the textures, most of the rest of PresentationContext is very simple; all it
has to do is track which texture is the current one.

Similarly, because the web process receives all of the backing IOSurfaces ahead of time when the canvas
got reconfigured, GPUCanvasContext doesn't have to do much beyond tracking which IOSurface is the
current one.

GPUCanvasContextCocoa::prepareForDisplay() calls CompositorIntegration::prepareForDisplay() which just
calls PresentationContext::present(). This is not quite enough, because prepareForDisplay() needs to
synchronously wait until all work has been scheduled, so we don't insert an incomplete frame into the
CoreAnimation layer tree. This improvement is being tracked at
https://bugs.webkit.org/show_bug.cgi?id=250993.

This patch deletes PresentationConfiguration, because it now is exactly identical to CanvasConfiguration,
and there's no need to have 2 configuration structs with the same contents and same purpose.

There's only really one more piece to this WebGPU compositing work, and that is to use
PresentationContext::getCurrentTexture() instead of Device::createSurfaceTexture(). I'll do that in an
upcoming patch.

* Source/WebCore/Modules/WebGPU/GPUCompositorIntegration.cpp:
(WebCore::GPUCompositorIntegration::recreateRenderBuffers const):
(WebCore::GPUCompositorIntegration::prepareForDisplay):
(WebCore::GPUCompositorIntegration::getRenderBuffers const): Deleted.
* Source/WebCore/Modules/WebGPU/GPUCompositorIntegration.h:
* Source/WebCore/Modules/WebGPU/GPUPresentationConfiguration.h: Removed.
* Source/WebCore/Modules/WebGPU/GPUPresentationContext.cpp:
(WebCore::GPUPresentationContext::configure):
* Source/WebCore/Modules/WebGPU/GPUPresentationContext.h:
* Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj:
* Source/WebCore/PAL/pal/CMakeLists.txt:
* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUCompositorIntegrationImpl.cpp:
(PAL::WebGPU::CompositorIntegrationImpl::prepareForDisplay):
(PAL::WebGPU::CompositorIntegrationImpl::recreateRenderBuffers):
(PAL::WebGPU::CompositorIntegrationImpl::getRenderBuffers): Deleted.
(PAL::WebGPU::CompositorIntegrationImpl::recreateIOSurfaces): Deleted.
* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUCompositorIntegrationImpl.h:
* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUConvertToBackingContext.h:
* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUImpl.cpp:
(PAL::WebGPU::GPUImpl::createPresentationContext):
* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUPresentationContextImpl.cpp:
(PAL::WebGPU::PresentationContextImpl::configure):
(PAL::WebGPU::PresentationContextImpl::unconfigure):
* Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUPresentationContextImpl.h:
* Source/WebCore/PAL/pal/graphics/WebGPU/WebGPUCompositorIntegration.h:
* Source/WebCore/PAL/pal/graphics/WebGPU/WebGPUPresentationConfiguration.h: Removed.
* Source/WebCore/PAL/pal/graphics/WebGPU/WebGPUPresentationContext.h:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/html/canvas/GPUCanvasContextCocoa.cpp:
(WebCore::getCanvasWidth):
(WebCore::getCanvasHeight):
(WebCore::GPUCanvasContextCocoa::GPUCanvasContextCocoa):
(WebCore::GPUCanvasContextCocoa::reshape):
(WebCore::GPUCanvasContextCocoa::configure):
(WebCore::GPUCanvasContextCocoa::unconfigure):
(WebCore::GPUCanvasContextCocoa::getCurrentTexture):
(WebCore::GPUCanvasContextCocoa::prepareForDisplay):
(WebCore::getCanvasSizeAsIntSize): Deleted.
(WebCore::GPUCanvasContextCocoa::unconfigurePresentationContextIfNeeded): Deleted.
(WebCore::GPUCanvasContextCocoa::configurePresentationContextIfNeeded): Deleted.
* Source/WebCore/html/canvas/GPUCanvasContextCocoa.h:
* Source/WebGPU/WebGPU/PresentationContext.h:
* Source/WebGPU/WebGPU/PresentationContext.mm:
(WebGPU::PresentationContext::unconfigure):
(wgpuSwapChainRelease):
* Source/WebGPU/WebGPU/PresentationContextCoreAnimation.h:
* Source/WebGPU/WebGPU/PresentationContextCoreAnimation.mm:
(WebGPU::PresentationContextCoreAnimation::unconfigure):
* Source/WebGPU/WebGPU/PresentationContextIOSurface.h:
(WebGPU::PresentationContextIOSurface::create): Deleted.
(WebGPU::PresentationContextIOSurface::displayBuffer const): Deleted.
(WebGPU::PresentationContextIOSurface::drawingBuffer const): Deleted.
* Source/WebGPU/WebGPU/PresentationContextIOSurface.mm:
(WebGPU::PresentationContextIOSurface::create):
(WebGPU::PresentationContextIOSurface::PresentationContextIOSurface):
(WebGPU::PresentationContextIOSurface::displayBuffer const):
(WebGPU::PresentationContextIOSurface::drawingBuffer const):
(WebGPU::PresentationContextIOSurface::renderBuffersWereRecreated):
(WebGPU::PresentationContextIOSurface::configure):
(WebGPU::PresentationContextIOSurface::unconfigure):
(WebGPU::PresentationContextIOSurface::present):
(WebGPU::PresentationContextIOSurface::getCurrentTexture):
(WebGPU::PresentationContextIOSurface::getCurrentTextureView):
(wgpuSurfaceCocoaCustomSurfaceGetDisplayBuffer):
(wgpuSurfaceCocoaCustomSurfaceGetDrawingBuffer):
(WebGPU::optionsFor32BitSurface): Deleted.
(WebGPU::createIOSurface): Deleted.
(WebGPU::createSurfaceFromDescriptor): Deleted.
(WebGPU::PresentationContextIOSurface::nextDrawable): Deleted.
* Source/WebGPU/WebGPU/Texture.h:
* Source/WebGPU/WebGPU/Texture.mm:
(WebGPU::Texture::usage):
(WebGPU::Device::createTexture):
(WebGPU::usage): Deleted.
* Source/WebGPU/WebGPU/WebGPUExt.h:
* Source/WebKit/CMakeLists.txt:
* Source/WebKit/DerivedSources.make:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteCompositorIntegration.cpp:
(WebKit::RemoteCompositorIntegration::recreateRenderBuffers):
(WebKit::RemoteCompositorIntegration::prepareForDisplay):
(WebKit::RemoteCompositorIntegration::getRenderBuffers): Deleted.
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteCompositorIntegration.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteCompositorIntegration.messages.in:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemotePresentationContext.cpp:
(WebKit::RemotePresentationContext::configure):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemotePresentationContext.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemotePresentationContext.messages.in:
* Source/WebKit/Scripts/webkit/messages.py:
(headers_for_type):
* Source/WebKit/Shared/WebGPU/WebGPUConvertFromBackingContext.h:
* Source/WebKit/Shared/WebGPU/WebGPUConvertToBackingContext.h:
* Source/WebKit/Shared/WebGPU/WebGPUPresentationConfiguration.cpp: Removed.
* Source/WebKit/Shared/WebGPU/WebGPUPresentationConfiguration.h: Removed.
* Source/WebKit/Shared/WebGPU/WebGPUPresentationConfiguration.serialization.in: Removed.
* Source/WebKit/Sources.txt:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteCompositorIntegrationProxy.cpp:
(WebKit::WebGPU::RemoteCompositorIntegrationProxy::recreateRenderBuffers):
(WebKit::WebGPU::RemoteCompositorIntegrationProxy::prepareForDisplay):
(WebKit::WebGPU::RemoteCompositorIntegrationProxy::getRenderBuffers): Deleted.
* Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteCompositorIntegrationProxy.h:
* Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemotePresentationContextProxy.cpp:
(WebKit::WebGPU::RemotePresentationContextProxy::configure):
* Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemotePresentationContextProxy.h:

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




More information about the webkit-changes mailing list