Bug 220476

Summary: [GPUProcess] Move DOM / Canvas rendering off the main thread in the GPUProcess
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebKit2Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cmarcelo, eric.carlson, ews-watchlist, ggaren, glenn, jer.noble, philipj, sergio, simon.fraser, thorton, webkit-bug-importer, wenson_hsieh, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=223033
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Chris Dumez 2021-01-08 12:52:27 PST
Move DOM / Canvas rendering off the main thread in the GPUProcess.

I am still waiting on A/B perf testing from the bots, but local testing seems to show this is likely perf-neutral:

===
* Rendering off the main thread:
146.87 +/- 9%
149.21 +/- 4%

* Rendering on main thread:
148.29 +/- 2%
145.89 +/- 8%
===

The good news though is that this architecture would allow us to block the thread on a semaphore more aggressively when waiting for new DisplayList entries. We currently are not able to be as aggressive as we'd like because we'd block the main thread.
Comment 1 Chris Dumez 2021-01-08 13:00:44 PST
Created attachment 417293 [details]
Patch
Comment 2 Simon Fraser (smfr) 2021-01-08 13:53:18 PST
Comment on attachment 417293 [details]
Patch

Does this move all ImageBuffer IPC receiving onto a single thread that's not the main thread?
Comment 3 Chris Dumez 2021-01-08 13:57:43 PST
(In reply to Simon Fraser (smfr) from comment #2)
> Comment on attachment 417293 [details]
> Patch
> 
> Does this move all ImageBuffer IPC receiving onto a single thread that's not
> the main thread?

It moves all *RemoteRenderingBackend* IPC receiving to a *serial workqueue* that's not the main thread. This means all the following IPC messages:
    CreateImageBuffer(WebCore::FloatSize logicalSize, WebCore::RenderingMode renderingMode, float resolutionScale, WebCore::ColorSpace colorSpace, enum:uint8_t WebCore::PixelFormat pixelFormat, WebCore::RenderingResourceIdentifier renderingResourceIdentifier)
    WakeUpAndApplyDisplayList(struct WebKit::GPUProcessWakeupMessageArguments arguments)
    GetImageData(enum:uint8_t WebCore::AlphaPremultiplication outputFormat, WebCore::IntRect srcRect, WebCore::RenderingResourceIdentifier renderingResourceIdentifier) -> (IPC::ImageDataReference imageData) Synchronous
    GetDataURLForImageBuffer(String mimeType, Optional<double> quality, enum:uint8_t WebCore::PreserveResolution preserveResolution, WebCore::RenderingResourceIdentifier renderingResourceIdentifier) -> (String urlString) Synchronous
    GetDataForImageBuffer(String mimeType, Optional<double> quality, WebCore::RenderingResourceIdentifier renderingResourceIdentifier) -> (Vector<uint8_t> data) Synchronous
    GetBGRADataForImageBuffer(WebCore::RenderingResourceIdentifier renderingResourceIdentifier) -> (Vector<uint8_t> data) Synchronous
    CacheNativeImage(WebKit::ShareableBitmap::Handle handle, WebCore::RenderingResourceIdentifier renderingResourceIdentifier)
    CacheFont(IPC::FontReference font)
    DeleteAllFonts()
    DidCreateSharedDisplayListHandle(WebCore::DisplayList::ItemBufferIdentifier identifier, WebKit::SharedMemory::IPCHandle handle, WebCore::RenderingResourceIdentifier destinationBufferIdentifier)
    ReleaseRemoteResource(WebCore::RenderingResourceIdentifier renderingResourceIdentifier)


I am not sure what you mean my ImageBuffer IPC. I don't know see a messages.in file corresponding to ImageBuffer specifically.
Comment 4 Tim Horton 2021-01-08 13:58:57 PST
RemoteRenderingBackend is the IPC proxy through which ImageBuffer work flows
Comment 5 Chris Dumez 2021-01-08 17:07:27 PST
Created attachment 417320 [details]
Patch
Comment 6 Chris Dumez 2021-01-11 08:25:03 PST
A/B testing came back. The current iteration of the patch seems to be a close to 1% regression on MotionMark unfortunately.
Comment 7 Chris Dumez 2021-01-11 17:28:11 PST
Created attachment 417422 [details]
Patch
Comment 8 Chris Dumez 2021-01-12 17:00:35 PST
Created attachment 417500 [details]
Patch
Comment 9 Chris Dumez 2021-01-12 22:12:16 PST
Created attachment 417508 [details]
Patch
Comment 10 Chris Dumez 2021-01-13 14:42:10 PST
Created attachment 417567 [details]
Patch
Comment 11 Chris Dumez 2021-01-13 14:54:26 PST
Created attachment 417568 [details]
Patch
Comment 12 Chris Dumez 2021-01-13 16:42:06 PST
Created attachment 417581 [details]
Patch
Comment 13 Chris Dumez 2021-01-15 08:55:33 PST
Ping review?
Comment 14 Radar WebKit Bug Importer 2021-01-15 12:53:21 PST
<rdar://problem/73260041>
Comment 15 EWS 2021-01-15 13:01:02 PST
Tools/Scripts/svn-apply failed to apply attachment 417581 [details] to trunk.
Please resolve the conflicts and upload a new patch.
Comment 16 Chris Dumez 2021-01-15 13:06:37 PST
Created attachment 417726 [details]
Patch
Comment 17 EWS 2021-01-15 13:51:57 PST
Committed r271533: <https://trac.webkit.org/changeset/271533>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 417726 [details].
Comment 18 youenn fablet 2021-01-18 07:07:50 PST
With this patch, RemoteRenderingBackend::cacheNativeImage is called in a background thread. This can call ShareableBitmap::createGraphicsContext which has an assertion to be called in main thread.
This reproduces for me by running webrtc/video.html with GPU process enabled in WTR/debug.
Comment 19 youenn fablet 2021-01-19 01:51:14 PST
(In reply to youenn fablet from comment #18)
> With this patch, RemoteRenderingBackend::cacheNativeImage is called in a
> background thread. This can call ShareableBitmap::createGraphicsContext
> which has an assertion to be called in main thread.
> This reproduces for me by running webrtc/video.html with GPU process enabled
> in WTR/debug.

https://build.webkit.org/results/Apple-Catalina-Debug-WK2-GPUProcess-Tests/r271596%20(5773)/results.html
Comment 20 Chris Dumez 2021-01-19 09:05:31 PST
(In reply to youenn fablet from comment #18)
> With this patch, RemoteRenderingBackend::cacheNativeImage is called in a
> background thread. This can call ShareableBitmap::createGraphicsContext
> which has an assertion to be called in main thread.
> This reproduces for me by running webrtc/video.html with GPU process enabled
> in WTR/debug.

Ok, will look now. Thanks.
Comment 21 Chris Dumez 2021-01-19 09:11:18 PST
(In reply to Chris Dumez from comment #20)
> (In reply to youenn fablet from comment #18)
> > With this patch, RemoteRenderingBackend::cacheNativeImage is called in a
> > background thread. This can call ShareableBitmap::createGraphicsContext
> > which has an assertion to be called in main thread.
> > This reproduces for me by running webrtc/video.html with GPU process enabled
> > in WTR/debug.
> 
> Ok, will look now. Thanks.

Follow-up in <https://trac.webkit.org/changeset/271601>.