How to use WebCL in Chrome?
For a Chrome version, Samsung's (the one on Google Code) is the right one to look at. It is for Safari: Safari is based on WebKit, which is also what Chrome is based on. Working with Chrome's renderer might be tricky, however, as I believe it is in a special process. I bet Chrome devs would love to help out on this, however, and I suggest checking with the WebCL project members if anybody has started looking at this already.
Feature-wise, Samsung's version has a big practical difference from Nokia's: it supports moving data directly from WebCL to WebGL. If you want to visualize a computation without going moving all the data off the GPU inbetween (which would kill real-time performance), this is a big deal.
Good luck!
(Jan 2020) There are other options to do web computation on the GPU:
WebGL compute shaders (old but readily accessible)
This is pretty easy to set up within a WebGL context. Shortcomings compared to WebCL are minor:
- WebCL Floating point precision guarantees are better (for most uses, doesn't matter)
- WebCL supports random writes where WebGL Compute doesn't, but for most parallel problems, this doesn't matter, as you'll be writing a result only for the current element operated on.
- Buffer data comes back to CPU as integers, but you can solve this if you represent your values the right way and encode/decode accordingly on the GPU/CPU. I've done this by multiplying floats by some large value (like 1024) before finalising in compute shader, and dividing by same once you get integers back on CPU (note that using a power of 2 means you can do this integer division very fast by doing
value = buffer[n] >> 10
i.e. 1024 = 2^10). I did not have any precision concerns as some scientific / fintech apps do.
You can find the recently-updated spec here.
WebGPU (new standard)
This is the latest standard under implementation, and successor to WebGL 1.0, 2.0 and WebCL.
You can access the GPU's computational power directly from JavaScript, dealing with latency on GPU callouts by using async
and await
. You will need to write shaders in WHLSL (now WSL), a new, high-level shader language based closely on Direct3D HLSL.
It abstracts the latest low-level 3D graphics APIs such as Metal, Vulkan and Direct3D 12, thereby reducing GPU overheads compared with Open/WebGL.
Choices?
WebGL compute shaders for those who intend to use computational results in WebGL rendering, who are anyway doing WebGL rendering in their app, or who want to prototype on web and then port to native OpenGL.
WebGPU for planned cross-browserness including on Apple devices (where GL has been poorly supported for a long time), newness, and speed. Also used for graphics.
WebCL via the extension for Chrome / Chromium if you ultimately want the opportunity to run the code on CPUs too, without modification, and don't need GPU rendering.