New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WorkerClient for WebCore to access WebKit from worker threads, and use it to create a RemoteRenderingBackendProxy per-thread #4085
Conversation
Full branch for extra context: https://github.com/mattwoodrow/WebKit/commits/eng/remote-rendering-workers |
EWS run on previous version of this PR (hash f71351e) |
I think this work could be simplified to first pursue the changes needed with It seems that we are lacking a per-worker factory for polymorphic object instantiations. I would start with:
2a. Investigate what is the object that workers use to configure the polymorphic objects via the global state. If there is none, add this interface alternatively 2b. Add logic for ChromeClient to hold per-thread GraphicsClients Small detail: E.g. there's Things that initially do not make sense to me:
This does not seem to be needed. To me, it appears as if we just need a RemoteRenderingBackendProxy per worker. Then we just need to make sure that the closure/crash support works if it doesn't work with the main connection. SerialDispatchQueue -- We already have WorkQueue, which is a serial dispatch queue. So the code about that doesn't make sense initially. Note: the implementation seems to be missing from this patch. |
We'd also need to add support to IPC::Connection for sending sync messages from the worker thread, and make sure responses are handled without touching/blocking the main thread. That's pretty complicated, with all the complexity we already have for handling unrelated messages while blocking for a sync message. Instead, I added support for creating new IPC::Connections that are bound to the worker thread (and can send sync messages from that thread), but don't support the re-entrant message handling (for simplicity, and we don't need that functionality for the current use case). This does require creating a new GPUConnectionToWebProcess though, bound to the IPC::Connection for the worker. This is all in #4043 (which is a dependency here, though GitHub doesn't let me express that in a useful way).
The implementation is in #4043. The functionality we're trying to represent here is 'the main thread, or a worker', that we can dispatch tasks to, assert that we're currently running in the expected place, and hold on to a reference to (could be weak, or strong). WorkQueue is a specific implementation, that neither the main thread or workers are. The closest existing thing that I can find is FunctionDispatcher (which isn't implemented by WorkerOrWorkletThread, but can be), but that doesn't offer refcounting, or assertions. |
Note that WorkQueue could implement the SerialDispatchQueue interface, but ConcurrentWorkQueue can't really, so it's a bit tricky. |
f71351e
to
73a4c71
Compare
EWS run on previous version of this PR (hash 73a4c71) |
Please note, only the top two commits are truly part of this PR. The others are just there because GitHub (and EWS) don't support dependent branches. |
73a4c71
to
03e85a2
Compare
03e85a2
to
2519ee1
Compare
EWS run on previous version of this PR (hash 2519ee1)
|
2519ee1
to
cb76e02
Compare
EWS run on previous version of this PR (hash cb76e02)
|
cb76e02
to
bd97b32
Compare
EWS run on previous version of this PR (hash bd97b32)
|
510d83b
to
7844c4a
Compare
EWS run on previous version of this PR (hash 7844c4a)
|
7844c4a
to
4904912
Compare
EWS run on previous version of this PR (hash 4904912)
|
Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp
Outdated
Show resolved
Hide resolved
class WebPage; | ||
class RemoteRenderingBackendProxy; | ||
|
||
class WebWorkerClient : public WebCore::WorkerClient { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many #if ENABLE(GPU_PROCESS)
in this header file and in the source file. Should not the GPUP case be moved to a new class named RemoteWebWorkerClient
which inherits from WebWorkerClient
? WebChromeClient::createWorkerClient()
will make the decision from the beginning so we do not have to deal with two different code paths in the same file.
|
||
RefPtr<ImageBuffer> ImageBuffer::sinkIntoBufferForDifferentThread() | ||
{ | ||
ASSERT(hasOneRef()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this always true? And what is the point in asserting it hasOneRef() and then create a new RefPtr of the ImageBuffer which will increment the ref count?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, the naming might not be great here.
It asserts that there's only one ref, because it's a private virtual and the only caller is the static which also asserts that it owns the only ref.
The default behaviour is that if the static owns the only ref to the ImageBuffer, then we can allow it to be passed to a new thread as-is since there won't be any other cross-thread references.
4904912
to
9d2f63b
Compare
EWS run on previous version of this PR (hash 9d2f63b)
|
9d2f63b
to
3aba2e8
Compare
EWS run on previous version of this PR (hash 3aba2e8)
|
3aba2e8
to
5d21d44
Compare
EWS run on previous version of this PR (hash 5d21d44)
|
5d21d44
to
7088983
Compare
EWS run on current version of this PR (hash 7088983)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To solve the most of the ifdefing problems, you can obtain the data needed by RemoteRenderingBackendCreationParameters expanded to the constructor args.
β¦d use it to create a RemoteRenderingBackendProxy per-thread https://bugs.webkit.org/show_bug.cgi?id=244828 Reviewed by Kimmo Kinnunen. Creates a new interface class WorkerClient (which implements GraphicsClient), for accessing WebKit graphics APIs from a worker thread. Adds an implementation of this in WebWorkerClient. Allocates an instance of (Web)WorkerClient for every dedicated and shared worker, and makes it available via WorkerGlobalScope. WebWorkerClient creates a dedicated GPUProcessConnection and RemoteRenderingBackendProx for each worker thread/instance, and uses this to create RemoteImageBufferProxys that are safe to use on that worker thread. * Source/WebCore/Headers.cmake: * Source/WebCore/page/Chrome.cpp: (WebCore::Chrome::createWorkerClient): * Source/WebCore/page/Chrome.h: * Source/WebCore/page/ChromeClient.h: (WebCore::ChromeClient::createWorkerClient): * Source/WebCore/page/WorkerClient.h: Added. * Source/WebCore/workers/DedicatedWorkerGlobalScope.cpp: (WebCore::DedicatedWorkerGlobalScope::create): (WebCore::DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope): * Source/WebCore/workers/DedicatedWorkerGlobalScope.h: * Source/WebCore/workers/DedicatedWorkerThread.cpp: (WebCore::DedicatedWorkerThread::createWorkerGlobalScope): * Source/WebCore/workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * Source/WebCore/workers/WorkerGlobalScope.h: (WebCore::WorkerGlobalScope::workerClient): * Source/WebCore/workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): * Source/WebCore/workers/WorkerThread.h: (WebCore::WorkerThread::setWorkerClient): (WebCore::WorkerThread::workerClient): * Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp: (WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope): * Source/WebCore/workers/shared/SharedWorkerGlobalScope.cpp: (WebCore::SharedWorkerGlobalScope::SharedWorkerGlobalScope): * Source/WebCore/workers/shared/SharedWorkerGlobalScope.h: * Source/WebCore/workers/shared/context/SharedWorkerThread.cpp: (WebCore::SharedWorkerThread::createWorkerGlobalScope): * Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.cpp: (WebCore::SharedWorkerThreadProxy::SharedWorkerThreadProxy): * Source/WebKit/Sources.txt: * Source/WebKit/WebKit.xcodeproj/project.pbxproj: * Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::createWorkerClient): * Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h: * Source/WebKit/WebProcess/WebCoreSupport/WebWorkerClient.cpp: Added. (WebKit::WebWorkerClient::WebWorkerClient): (WebKit::WebWorkerClient::ensureRenderingBackend const): (WebKit::WebWorkerClient::clone): (WebKit::WebWorkerClient::displayID const): (WebKit::WebWorkerClient::createImageBuffer const): * Source/WebKit/WebProcess/WebCoreSupport/WebWorkerClient.h: Added. Canonical link: https://commits.webkit.org/257507@main
7088983
to
280e6cd
Compare
Committed 257507@main (280e6cd): https://commits.webkit.org/257507@main Reviewed commits have been landed. Closing PR #4085 and removing active labels. |
280e6cd
7088983