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

Added a sample that shows WebGPU running from a web worker #289

Merged
merged 3 commits into from
Aug 10, 2023
Merged

Conversation

toji
Copy link
Contributor

@toji toji commented Aug 4, 2023

This is a pretty simple sample, but it's covering a subject that I've seen a couple of questions about and I think i's useful to have readily available as a sanity check to ensure this method of using WebGPU works.

The sample itself is basically just a copy of the rotating cube sample, but with all the WebGPU code executing from a worker rather than the main thread. canvas.transferToOffscreen() is used to produce an OffscreenCanvas on the main thread that's then transferred to the worker and used for rendering. The frame loop is managed worker-side with requestAnimationFrame().

If we feel it's useful we could set up variants/options for this sample that use the transferToImageBitmap() pattern for rendering and a main-thread-driven rendering loop, but I think it's probably OK to have it focus on simply demonstrating that you can use WebGPU in a worker.

@toji toji requested review from austinEng and lokokung August 4, 2023 23:45
@toji
Copy link
Contributor Author

toji commented Aug 5, 2023

Hm... build checks think that transferControlToOffscreen() doesn't exist. CanIUse begs to differ. 😉

Any browser that implements WebGPU will also have this API, so I think it's a non-issue. I'll look into how to suppress that error later, probably Monday.

@kainino0x
Copy link
Collaborator

Hm... build checks think that transferControlToOffscreen() doesn't exist. CanIUse begs to differ. 😉

It was removed in TypeScript 4.4
microsoft/TypeScript@9ebe11c
microsoft/TypeScript-DOM-lib-generator#1029
and added back in 4.9.
microsoft/TypeScript@170a17f

Should just need to upgrade to 4.9 or newer.

@toji
Copy link
Contributor Author

toji commented Aug 5, 2023

Done. updated to the last 4.x revision (4.9.5)

@toji
Copy link
Contributor Author

toji commented Aug 9, 2023

Friendly Ping!

@toji toji merged commit 8c86ccf into main Aug 10, 2023
1 check passed
@toji toji deleted the worker branch August 10, 2023 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants