gpu.js icon indicating copy to clipboard operation
gpu.js copied to clipboard

WebWorker backend support

Open fuzzie360 opened this issue 10 years ago • 9 comments

Use the WebWorker API to run the kernel on CPU cores.

Challenges:

  • WebWorkers are purely asynchronous. Blocked by #4 for API parity among all backends which might break graceful fallback.

fuzzie360 avatar Feb 19 '16 11:02 fuzzie360

Couldn't one just load gpu in the webworker? Done!

robertleeplummerjr avatar Jul 05 '17 00:07 robertleeplummerjr

As a general update to this enhancement, I think API-wise, maybe we should just return a Promise just like how we just return a Texture object anyway. To support graceful fallback, we could implement an async unrwraper to turn our different output types (Arrays, Promises, Textures) into Arrays.

@robertleeplummerjr what you are describing requires this tho https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas It would actually improve the user experience for our normal GPU kernels by allowing JavaScript to execute something while awaiting for a response from GPU, But, WebWorkers also improve CPU performance which is something we could try and achieve too.

fuzzie360 avatar Jul 16 '17 02:07 fuzzie360

I was more thinking just cpu fallback in webworker, but your recommendation is a touché to my angarde.

robertleeplummerjr avatar Jul 16 '17 02:07 robertleeplummerjr

Just chiming in to say I would love to be able to run GPU.js in a webworker on a GPU. Too bad only Firefox supports webgl in a webworker at this point https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas#Browser_compatibility

ubernaut avatar Feb 23 '18 17:02 ubernaut

agreed. I have a feeling that will be the case for only a short time. It is just too good of a feature.

robertleeplummerjr avatar Feb 23 '18 17:02 robertleeplummerjr

wait a tick... basic support?
offscreencanvas - web apis mdn

robertleeplummerjr avatar Feb 23 '18 17:02 robertleeplummerjr

Is gpu.js usable in a web worker?

feljx avatar Apr 15 '20 21:04 feljx

Unit tests: https://github.com/gpujs/gpu.js/blob/5397186a7ae1e901f504f7682be684cc5572d2c5/test/features/offscreen-canvas.js#L19

robertleeplummerjr avatar Apr 15 '20 21:04 robertleeplummerjr

I believe this to be working.

robertleeplummerjr avatar Mar 28 '22 14:03 robertleeplummerjr