emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

--proxy-to-worker forces WebGL to rollback to 1.0?

Open ziocleto opened this issue 8 years ago • 4 comments

I've read about WebGL being implemented on web workers on issue #2396 but that was 3 years ago.

Now if I use --proxy-to-worker I can see that there's an attempt to map webGL functions into a GLctx but it's incomplete for WebGL2.0 as functions as bindBufferBase are not present.

By querying OpenGL capabilities at startup I also obtain 2 different outputs:

With --proxy-to-worker:

WebKit WebGL WebGL 1.0 (OpenGL ES 2.0 Chromium) OpenGL ES GLSL ES 1.00 (WebGL GLSL ES 1.0 (OpenGL ES GLSL ES 1.0 Chromium))

No --proxy-to-worker:

WebKit WebGL OpenGL ES 3.0 (WebGL 2.0 (OpenGL ES 3.0 Chromium)) OpenGL ES GLSL ES 3.00 (WebGL GLSL ES 3.00 (OpenGL ES GLSL ES 3.0 Chromium))

(There's also a bug querying GL_VERSION inside worker.js but that's for another day)

ziocleto avatar Dec 21 '17 12:12 ziocleto

Yes, the WebGL proxying was written before WebGL 2.0, and it has not been updated. It might make sense to improve that, but another option will eventually be to use threads, @juj is working on running GL from a background thread, including with proxy-to-worker, and I think that will work with WebGL 2.0.

kripken avatar Dec 21 '17 18:12 kripken

There is a fundamental web spec limitation with proxying via postMessage that all proxying needs to be asynchronous, and synchronous proxying is not possible. This restricts the extent that --proxy-to-worker can perform proxying of WebGL, and it's more an experimental work rather than something that one could rely on in a stable manner. This proxying was implemented in WebGL 1 era, and after WebGL 2 came out, because of the limitations, nobody has had much interest in expanding it to WebGL 2, so WebGL 2 does not work like you're seeing. (If you're interested, feel free to submit patches)

The proper way we'll get WebGL 1 & 2 to Web Workers / pthreads is to use SharedArrayBuffer and OffscreenCanvas. This support will be proper and gives all the features. You can try it out today if you link with -s OFFSCREENCANVAS=1 and/or -s PROXY_TO_PTHREAD=1, although this may be a bit too early, since neither OffscreenCanvas and SharedArrayBuffer-in-Wasm has yet shipped, so you'll need a Firefox Nightly or a Chrome Canary to test this out.

juj avatar Dec 21 '17 18:12 juj

Ah ok thanks that makes sense I wasn't sure if I was doing something wrong.

I think it makes sense to go straight into pthreads and shared memory on WASM, I would help (I've done graphics programming for video games for about 20 years at EA and Sony) but I'm a total newby on javascript so I'll just watch it for the time being.

ziocleto avatar Dec 21 '17 18:12 ziocleto

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.

stale[bot] avatar Sep 19 '19 05:09 stale[bot]