Bug 217554 - [GPU Process][Resource caching 2/7]: Introduce RemoteResourceCache to manage the resources in the GPU Process
Summary: [GPU Process][Resource caching 2/7]: Introduce RemoteResourceCache to manage ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Said Abou-Hallawa
URL:
Keywords: InRadar
Depends on: 217550
Blocks: 217342 217558
  Show dependency treegraph
 
Reported: 2020-10-09 20:44 PDT by Said Abou-Hallawa
Modified: 2020-10-16 23:46 PDT (History)
13 users (show)

See Also:


Attachments
Patch (68.67 KB, patch)
2020-10-09 20:53 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch for review (37.46 KB, patch)
2020-10-09 21:43 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (52.82 KB, patch)
2020-10-12 23:55 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (48.49 KB, patch)
2020-10-15 10:44 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (62.56 KB, patch)
2020-10-16 17:16 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (66.29 KB, patch)
2020-10-16 20:06 PDT, Said Abou-Hallawa
simon.fraser: review+
Details | Formatted Diff | Diff
Patch (66.43 KB, patch)
2020-10-16 22:52 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Said Abou-Hallawa 2020-10-09 20:44:10 PDT
RemoteRenderingBackendProxy will own an instance of RemoteResourceCacheProxy. One type of these resources will be the RemoteImageBufferProxy. We can split the responsibilities of the remote rendering among these classes like this:

-- RemoteRenderingBackendProxy: is responsible for sending messages to and receiving messages from the RemoteRenderingBackend. It will delegate all the resource management to its RemoteResourceCacheProxy
-- RemoteResourceCacheProxy: is responsible for managing the remote resources including the actual life cycle of these resources.
-- RemoteImageBufferProxy: is responsible for the ImageBuffer functionalities taking into consideration it is a remote resource, i.e drawing is recorded in WebProcess and backend lives in the GPU Process.

This makes it easy to get rid of RemoteImageBufferMessageHandlerProxy because all it does is sending messages to WebProcess but we can simplify the interface of RemoteImageBufferProxy by removing it and moving sending the messages to RemoteRenderingBackendProxy.
Comment 1 Said Abou-Hallawa 2020-10-09 20:53:19 PDT
Created attachment 411005 [details]
Patch
Comment 2 Said Abou-Hallawa 2020-10-09 21:43:19 PDT
Created attachment 411006 [details]
Patch for review
Comment 3 Simon Fraser (smfr) 2020-10-12 16:01:29 PDT
Comment on attachment 411006 [details]
Patch for review

View in context: https://bugs.webkit.org/attachment.cgi?id=411006&action=review

> Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:74
> +void RemoteRenderingBackendProxy::remoteCreateImageBufferBackend(const FloatSize& logicalSize, const IntSize& backendSize, float resolutionScale, ColorSpace colorSpace, ImageBufferBackendHandle handle, RemoteResourceIdentifier remoteResourceIdentifier)

Or createRemoteImageBufferBackend?

Does this have to do IPC? Could we create the image buffer backend lazily the first time it's referenced by something?

> Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp:76
> +    if (auto image = flushDrawingContext(displayList, remoteResourceIdentifier)) {
> +        image->flushContext();

It's confusing that we have both flushDrawingContext() and flushContext(), but we also have the "commit" terminology for flushContext().

> Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.h:50
> +    WebCore::ImageBuffer* flushDrawingContext(const WebCore::DisplayList::DisplayList&, WebCore::RemoteResourceIdentifier);
> +    WebCore::ImageBuffer* flushDrawingContextAndCommit(const WebCore::DisplayList::DisplayList&, WebCore::RemoteResourceIdentifier);

I'm a bit confused by flushDrawing() need to take a DisplayList argument. In my mind, "flush" means "execute drawing commands that you've already received".

> Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.h:58
> +    RemoteImageBufferHashMap m_remoteImageBufferHashMap;

Don't put "HashMap" in the name. Maybe m_identifierToBufferMap, or just m_imageBuffers.
Comment 4 Said Abou-Hallawa 2020-10-12 23:55:13 PDT
Created attachment 411199 [details]
Patch
Comment 5 Said Abou-Hallawa 2020-10-13 00:03:55 PDT
Comment on attachment 411006 [details]
Patch for review

View in context: https://bugs.webkit.org/attachment.cgi?id=411006&action=review

>> Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:74
>> +void RemoteRenderingBackendProxy::remoteCreateImageBufferBackend(const FloatSize& logicalSize, const IntSize& backendSize, float resolutionScale, ColorSpace colorSpace, ImageBufferBackendHandle handle, RemoteResourceIdentifier remoteResourceIdentifier)
> 
> Or createRemoteImageBufferBackend?
> 
> Does this have to do IPC? Could we create the image buffer backend lazily the first time it's referenced by something?

Name was changed. Eventually we will not send this message to the Web Process because we do not want it to have access to the backend. We need it now because the canvas ImageBuffer is still drawn to the layer in Web Process which should not happen.

>> Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp:76
>> +        image->flushContext();
> 
> It's confusing that we have both flushDrawingContext() and flushContext(), but we also have the "commit" terminology for flushContext().

I renamed it to applyDisplayList() since all RemoteImageBufferProxy does is applying a DisplayList to the backend.

>> Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.h:58
>> +    RemoteImageBufferHashMap m_remoteImageBufferHashMap;
> 
> Don't put "HashMap" in the name. Maybe m_identifierToBufferMap, or just m_imageBuffers.

Done.
Comment 6 Simon Fraser (smfr) 2020-10-14 11:23:25 PDT
Comment on attachment 411199 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=411199&action=review

> Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:76
> +    send(Messages::RemoteRenderingBackend::CreateRemoteImageBufferBackend(logicalSize, backendSize, resolutionScale, colorSpace, WTFMove(handle), remoteResourceIdentifier), m_renderingBackendIdentifier);

Do we need separate IPC to create the remote buffer backend, or can we just create them when first referenced, and send the IDs in a reply?

> Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:79
> +void RemoteRenderingBackendProxy::commitApplyDisplayList(ImageBufferFlushIdentifier flushIdentifier, RemoteResourceIdentifier remoteResourceIdentifier)

"commitApply" is weird naming. Can this just use 'flush"?

> Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp:41
> +void RemoteResourceCacheProxy::createImageBuffer(const FloatSize& logicalSize, RenderingMode renderingMode, float resolutionScale, ColorSpace colorSpace, RemoteResourceIdentifier remoteResourceIdentifier)

Should the cache be the one to create the buffer? Normally you just add things to caches, not have the cache create things.

> Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp:75
> +        image->flushContext();
> +        m_remoteRenderingBackendProxy.commitApplyDisplayList(flushIdentifier, remoteResourceIdentifier);

The mixture of "commit" and "flush" is confusing here.

Should the function on m_remoteRenderingBackendProxy be called didFlushDrawingForResource?

> Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp:79
> +RefPtr<ImageData> RemoteResourceCacheProxy::getImageData(AlphaPremultiplication outputFormat, const IntRect& srcRect, RemoteResourceIdentifier remoteResourceIdentifier) const

This doesn't seem like it should live on the resource cache.
Comment 7 Said Abou-Hallawa 2020-10-15 10:44:32 PDT
Created attachment 411459 [details]
Patch
Comment 8 Said Abou-Hallawa 2020-10-15 11:03:54 PDT
Comment on attachment 411199 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=411199&action=review

>> Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:76
>> +    send(Messages::RemoteRenderingBackend::CreateRemoteImageBufferBackend(logicalSize, backendSize, resolutionScale, colorSpace, WTFMove(handle), remoteResourceIdentifier), m_renderingBackendIdentifier);
> 
> Do we need separate IPC to create the remote buffer backend, or can we just create them when first referenced, and send the IDs in a reply?

When ImageBuffer::create() is called for a GPU based ImageBuffer, we have to create an instance of RemoteImageBuffer. RemoteImageBuffer offers the GraphicsContext which is backed by a DisplayList::Recorder. Usually the caller will not need the backend immediately because it has to draw first. At this time RemoteImageBufferProxy is created in GPU Process and it sends its ImageBufferHandle to RemoteImageBuffer. So this workflow works nicely with the common case of using ImageBuffer and at the same time it is asynchronous. So I am not sure why do we have to delay sending this message till the backend is needed? This should cause a delay while sending the message, waiting for the replay and creating the backend.

>> Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:79
>> +void RemoteRenderingBackendProxy::commitApplyDisplayList(ImageBufferFlushIdentifier flushIdentifier, RemoteResourceIdentifier remoteResourceIdentifier)
> 
> "commitApply" is weird naming. Can this just use 'flush"?

Function was renamed commitFlushDisplayList().

>> Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp:41
>> +void RemoteResourceCacheProxy::createImageBuffer(const FloatSize& logicalSize, RenderingMode renderingMode, float resolutionScale, ColorSpace colorSpace, RemoteResourceIdentifier remoteResourceIdentifier)
> 
> Should the cache be the one to create the buffer? Normally you just add things to caches, not have the cache create things.

I was seeing RemoteResourceCacheProxy not only a resource cache but also a resource manager. But having the "Cache" in the name makes it confusing to make it create the objects as well. So I moved creating the ImageBuffers back to RemoteRenderingBackendProxy.

>> Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp:75
>> +        m_remoteRenderingBackendProxy.commitApplyDisplayList(flushIdentifier, remoteResourceIdentifier);
> 
> The mixture of "commit" and "flush" is confusing here.
> 
> Should the function on m_remoteRenderingBackendProxy be called didFlushDrawingForResource?

I moved this function back to RemoteRenderingBackendProxy.

>> Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp:79
>> +RefPtr<ImageData> RemoteResourceCacheProxy::getImageData(AlphaPremultiplication outputFormat, const IntRect& srcRect, RemoteResourceIdentifier remoteResourceIdentifier) const
> 
> This doesn't seem like it should live on the resource cache.

I moved this function back to RemoteRenderingBackendProxy.
Comment 9 Said Abou-Hallawa 2020-10-16 17:16:54 PDT
Created attachment 411634 [details]
Patch
Comment 10 Simon Fraser (smfr) 2020-10-16 18:43:21 PDT
(In reply to Said Abou-Hallawa from comment #8)
> Comment on attachment 411199 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=411199&action=review
> 
> >> Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:76
> >> +    send(Messages::RemoteRenderingBackend::CreateRemoteImageBufferBackend(logicalSize, backendSize, resolutionScale, colorSpace, WTFMove(handle), remoteResourceIdentifier), m_renderingBackendIdentifier);
> > 
> > Do we need separate IPC to create the remote buffer backend, or can we just create them when first referenced, and send the IDs in a reply?
> 
> When ImageBuffer::create() is called for a GPU based ImageBuffer, we have to
> create an instance of RemoteImageBuffer. RemoteImageBuffer offers the
> GraphicsContext which is backed by a DisplayList::Recorder. Usually the
> caller will not need the backend immediately because it has to draw first.
> At this time RemoteImageBufferProxy is created in GPU Process and it sends
> its ImageBufferHandle to RemoteImageBuffer. So this workflow works nicely
> with the common case of using ImageBuffer and at the same time it is
> asynchronous. So I am not sure why do we have to delay sending this message
> till the backend is needed? This should cause a delay while sending the
> message, waiting for the replay and creating the backend.

This is in GPUProcess/graphics/RemoteRenderingBackendProxy, so I assume it's sending IPC from GPU to WebProcess, which is confusing because the WebProcess should be the one creating buffer proxies which are then materialized in the GPU process.

> 
> >> Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:79
> >> +void RemoteRenderingBackendProxy::commitApplyDisplayList(ImageBufferFlushIdentifier flushIdentifier, RemoteResourceIdentifier remoteResourceIdentifier)
> > 
> > "commitApply" is weird naming. Can this just use 'flush"?
> 
> Function was renamed commitFlushDisplayList().

Not ideal but we can wordsmith later.

> >> Source/WebKit/GPUProcess/graphics/RemoteResourceCacheProxy.cpp:41
> >> +void RemoteResourceCacheProxy::createImageBuffer(const FloatSize& logicalSize, RenderingMode renderingMode, float resolutionScale, ColorSpace colorSpace, RemoteResourceIdentifier remoteResourceIdentifier)
> > 
> > Should the cache be the one to create the buffer? Normally you just add things to caches, not have the cache create things.
> 
> I was seeing RemoteResourceCacheProxy not only a resource cache but also a
> resource manager. But having the "Cache" in the name makes it confusing to
> make it create the objects as well. So I moved creating the ImageBuffers
> back to RemoteRenderingBackendProxy.

Seems better.
Comment 11 Said Abou-Hallawa 2020-10-16 20:06:07 PDT
Created attachment 411645 [details]
Patch
Comment 12 Said Abou-Hallawa 2020-10-16 20:06:55 PDT
Comment on attachment 411199 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=411199&action=review

>>>> Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:76
>>>> +    send(Messages::RemoteRenderingBackend::CreateRemoteImageBufferBackend(logicalSize, backendSize, resolutionScale, colorSpace, WTFMove(handle), remoteResourceIdentifier), m_renderingBackendIdentifier);
>>> 
>>> Do we need separate IPC to create the remote buffer backend, or can we just create them when first referenced, and send the IDs in a reply?
>> 
>> When ImageBuffer::create() is called for a GPU based ImageBuffer, we have to create an instance of RemoteImageBuffer. RemoteImageBuffer offers the GraphicsContext which is backed by a DisplayList::Recorder. Usually the caller will not need the backend immediately because it has to draw first. At this time RemoteImageBufferProxy is created in GPU Process and it sends its ImageBufferHandle to RemoteImageBuffer. So this workflow works nicely with the common case of using ImageBuffer and at the same time it is asynchronous. So I am not sure why do we have to delay sending this message till the backend is needed? This should cause a delay while sending the message, waiting for the replay and creating the backend.
> 
> This is in GPUProcess/graphics/RemoteRenderingBackendProxy, so I assume it's sending IPC from GPU to WebProcess, which is confusing because the WebProcess should be the one creating buffer proxies which are then materialized in the GPU process.

RemoteRenderingBackendProxy messages were renamed: ImageBufferBackendWasCreated and FlushDisplayListWasCommitted.
Comment 13 Radar WebKit Bug Importer 2020-10-16 20:45:20 PDT
<rdar://problem/70401828>
Comment 14 Said Abou-Hallawa 2020-10-16 22:52:13 PDT
Created attachment 411656 [details]
Patch
Comment 15 EWS 2020-10-16 23:46:30 PDT
Committed r268637: <https://trac.webkit.org/changeset/268637>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 411656 [details].