Skip to content
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

WebGPU: ServiceWorker and SharedWorker support #971

Open
beaufortfrancois opened this issue Jan 29, 2024 · 3 comments
Open

WebGPU: ServiceWorker and SharedWorker support #971

beaufortfrancois opened this issue Jan 29, 2024 · 3 comments

Comments

@beaufortfrancois
Copy link

Request for Mozilla Position on an Emerging Web Specification

Other information

ServiceWorker and SharedWorker support have not yet been implemented in any browser, but have been approved by the GPU for the Web Community Group, with representatives from Chrome, Firefox, and Safari. See minutes.

@asutherland
Copy link
Member

This should definitely be fine on SharedWorker.

For ServiceWorkers we've tried to avoid exposing blocking / synchronous APIs because they defeat the point of a ServiceWorker being able to process events in a timely fashion. (And even though WebExtensions MV3 has blurred the meaning of ServiceWorkers, they have still been repurposed to respond to events in a timely fashion, so the original rationale holds up.) In those cases of blocking APIs, enabling nested workers in ServiceWorkers has been proposed at w3c/ServiceWorker#1529 in the SW WG and whatwg/html#8362 in HTML.

Since it seems like the API is explicitly async, I think the question then becomes one of whether data (de)serialization needs to happen on the API thread, and if so if general idioms would take appreciable time. (For example, a common problem for people trying to throw workers at things is just the immense overhead of structured serialization of a complex object graph which inherently needs to happen synchronously with respect to the global.) My presumption would be WebGPU can be implemented in such a way that (de)serialization is not as much of a concern and that the API calls might have a similar level of expense as structured serialization, but that's an argument for just letting the API calls happen in the SW rather than adding the overhead to postMessage to a nested dedicated worker (which we don't yet have).

That said, it would definitely be good to get a Gecko WebGPU domain expert to confirm that we don't expect general usage to interfere with a ServiceWorker's responsiveness.

@jimblandy
Copy link

WebGPU doesn't have any expensive synchronous operations in the JS process. Everything is designed to be streamed to the GPU process. There is no synchronous readback in WebGPU, like WebGL's readPixels: WebGPU's analogous mapAsync returns a promise that is resolved when the requested data is available in the caller's process.

Firefox's WebGPU implementation uses IPDL shared memory to transfer large data (GPUBuffer contents) to the GPU process. WebGPU Shading Language (WGSL) programs - source code for programs to be run on the GPU - are transferred to the GPU process as IPDL nsCString values. Generally, the structures being transferred over IPDL like GPUBindGroupDescriptor are not especially large.

@asutherland Does that answer your questions?

@asutherland
Copy link
Member

Yeah, sounds fine then. Thanks for the expert context!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Unscreened
Development

No branches or pull requests

3 participants