oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.13k stars 2.76k forks source link

WebGPU support #7380

Open birkskyum opened 11 months ago

birkskyum commented 11 months ago

What is the problem this feature would solve?

Unit testing / server rendering of webgpu canvas

What is the feature you are proposing to solve the problem?

I propose for bun to use an off-the-shelf webgpu implementation (like wgpu or dawn), to provide access to a DOM / canvas Web API.

What alternatives have you considered?

The alternative would be from bun to spawn playwright/puppeteer browser, inject the code there to run it in chromium, and then try to exact it into bun and use it in the bun test.

birkskyum commented 10 months ago

WebGPU was recently added to Deno, opening up i.e. usage of GPU accelerated ML frameworks like tensorflow.js server-side. Would be cool to be able to do such things with bun as well.

sroussey commented 10 months ago

There is an implementation of webgpu in webkit now.

Ref: https://webkit.org/blog/14879/webgpu-now-available-for-testing-in-safari-technology-preview/

Jarred-Sumner commented 10 months ago

We are unlikely to add WebGPU support to Bun in any official capacity until WebGPU is far more widely used. This is a great usecase for napi.

sroussey commented 10 months ago

WebLLM uses wasm combined with webgpu. I’m not sure a node napi would suffice, but it might… I’ll have to see how they connect them.

Generally speaking, I think if bun had great ai primitives (or direct support for those that do) it would be a force multiplier.

Jarred-Sumner commented 10 months ago

WebGPU is not a great AI primitive, imo. It happens to work for that usecase, but it is not designed for that usecase. It would be better to support something designed for AI/LLMs, but it's unclear what that is right now

birkskyum commented 10 months ago

AI aside, it would be very relevant for server side rendering of webgpu still, such as unit testing for maplibre-gl, which currently has jest tests with webgl rendering (through headless-gl)

mourner commented 8 months ago

I'd love to see this in Bun too, at least once WebGPU ships unflagged in Webkit like it did in Chrome last year. This would be perfect for headless automated testing of 3D applications, e.g. ones that use Three.js or Babylon.js with WebGPU backend.

Examples of how this is used in Deno for reference: https://github.com/denoland/webgpu-examples/ And this is how a similar thing is set up with Puppeteer (but it's a bit involved and limited): https://developer.chrome.com/blog/supercharge-web-ai-testing

wcldyx commented 1 week ago

Is this function being developed?