You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 33bdc3c
Browse filesBrowse the repository at this point in the historyBrowse files
Reuse WebGL drawing buffers once the compositor releases them
https://bugs.webkit.org/show_bug.cgi?id=327571
rdar://190042989
Reviewed by Kimmo Kinnunen.
For a WebGL context we keep a ring of three drawing buffers: front (display),
back (drawing), and a secondary back buffer. Each frame the ring moves on to the
buffer sent two frames earlier, and if it is still in use, destroys it and
allocates a new one. On Apple platforms the compositor keeps a displayed buffer
for about 4 frames at both 60 and 120 FPS. So if a canvas is rendering every
frame a buffer gets released and a new one allocated every frame. This is quite
expensive since the kernel needs to allocate memory and map it in to the GPU
process and then destroy an old one on the next frame.
Keep two extra buffers as a spares instead. Once a spare is no longer in use it
becomes available and marked volatile. The next time the ring needs a buffer it
takes the earliest unused spare, and only allocates if there are none.
So that the last few buffers are not left non-volatile once a canvas stops
drawing, RemoteGraphicsContextGLCocoa schedules a check 200 ms after a frame
that leaves a spare in-use. If no frame came in the mean time, it makes the
released spares volatile and drops any that are still in-use to save memory on
a static page.
Measured on an iPhone 16 Pro with one 1902x1440 WebGL2 canvas, while animating
the allocation churn drops from one per frame to a total of 5 at 60Hz and 6 at
120Hz over the course of about 75 seconds. GPU process CPU drops by about 43%
at 60 Hz and about 45% at 120 Hz. The Web process's peak footprint goes down
by 21 MB at 60 Hz and 13 MB at 120 Hz, and once the canvas stops drawing its
footprint is the same as before this patch.
Tests: TestWebKitAPI.GraphicsContextGLCocoaTest/AnyContextAttributeTest.DisplayBuffersInUseAreReusedOnceReleased
TestWebKitAPI.GraphicsContextGLCocoaTest/AnyContextAttributeTest.IdleSpareDrawingBuffersAreReleased
TestWebKitAPI.GraphicsContextGLCocoaTest/AnyContextAttributeTest.SpareDrawingBuffersAreDroppedOnReshapeAndColorSpaceChange
* Source/WTF/wtf/spi/cocoa/IOSurfaceSPI.h:
Add declaration needed for tests.
* Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h:
* Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
(WebCore::GraphicsContextGLCocoa::copySurfaceBuffer):
(WebCore::GraphicsContextGLCocoa::createDrawingBuffer):
(WebCore::GraphicsContextGLCocoa::createPbuffer):
(WebCore::GraphicsContextGLCocoa::bindNextDrawingBuffer):
(WebCore::GraphicsContextGLCocoa::freeDrawingBuffers):
(WebCore::GraphicsContextGLCocoa::retireDrawingBuffer):
(WebCore::GraphicsContextGLCocoa::takeSpareDrawingBuffer):
(WebCore::GraphicsContextGLCocoa::updateSpareDrawingBuffers):
(WebCore::GraphicsContextGLCocoa::hasSpareDrawingBuffersInUse const):
(WebCore::GraphicsContextGLCocoa::releaseIdleSpareDrawingBuffers):
* Source/WebCore/platform/graphics/cocoa/IOSurfaceDrawingBuffer.h:
(WebCore::IOSurfaceDrawingBuffer::takeSurface):
* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp:
(WebKit::RemoteGraphicsContextGLCocoa::prepareForDisplay):
(WebKit::RemoteGraphicsContextGLCocoa::scheduleIdleSpareDrawingBufferRelease):
(WebKit::RemoteGraphicsContextGLCocoa::idleSpareDrawingBufferReleaseTimerFired):
* Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm:
(TestWebKitAPI::WebCore::TestedGraphicsContextGLCocoa::spareDrawingBufferCount const):
(TestWebKitAPI::WebCore::TestedGraphicsContextGLCocoa::volatileSpareDrawingBufferCount const):
(TestWebKitAPI::TEST_P):
(TestWebKitAPI::displayFramesKeepingBuffersInUse):
(TestWebKitAPI::releaseBuffers):
* WebKitLibraries/SDKs/watchos26.0-additions.sdk/System/Library/Frameworks/IOSurface.framework/IOSurface.tbd:
* WebKitLibraries/SDKs/watchos27.0-additions.sdk/System/Library/Frameworks/IOSurface.framework/IOSurface.tbd:
* WebKitLibraries/SDKs/watchsimulator26.0-additions.sdk/System/Library/Frameworks/IOSurface.framework/IOSurface.tbd:
watchOS public SDK does not come with IOSurfaceDecrementUseCount which is needed for the new tests.
Canonical link: https://commits.webkit.org/323882@main
0 commit comments