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

Emscripten wgpu-hal example is broken #3245

Closed
jimblandy opened this issue Nov 29, 2022 · 10 comments
Closed

Emscripten wgpu-hal example is broken #3245

jimblandy opened this issue Nov 29, 2022 · 10 comments
Labels
api: gles Issues with GLES or WebGL type: bug Something isn't working

Comments

@jimblandy
Copy link
Member

When I build wgpu-hal/examples/raw-gles.rs according to the instructions in #2422, I get the following error in the page's console:

This page is in Quirks Mode. Page layout may be impacted. For Standards Mode use “<!DOCTYPE html>”.
[raw-gles.em.html](http://localhost:8000/raw-gles.em.html)
GEThttp://localhost:8000/favicon.ico
[HTTP/1.0 404 File not found 1ms]

Initializing external GL context [raw-gles.js:1799:16](http://localhost:8000/raw-gles.js)
Hooking up to wgpu-hal [raw-gles.js:1799:16](http://localhost:8000/raw-gles.js)
thread 'main' panicked at 'Get parameter string 0x9245 failed. Maybe your GL context version is too outdated.', /home/jimb/.cargo/git/checkouts/glow-0323f9242b6190b5/c8a011f/src/native.rs:1181:13 [raw-gles.js:1811:16](http://localhost:8000/raw-gles.js)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace [raw-gles.js:1811:16](http://localhost:8000/raw-gles.js)
WebGL warning: getParameter: Bad `pname`: 0x9245

I'm building and serving the page as follows:

$  cargo clean
$  EMCC_CFLAGS="-g -s ERROR_ON_UNDEFINED_SYMBOLS=0 --no-entry -s FULL_ES3=1" cargo build --example raw-gles --target wasm32-unknown-emscripten --features gles,emscripten,webgl
$  cp wgpu-hal/examples/raw-gles.em.html target/wasm32-unknown-emscripten/debug/examples/
$  cd target/wasm32-unknown-emscripten/debug/examples/
$  python -m http.server
@jimblandy jimblandy added type: bug Something isn't working api: gles Issues with GLES or WebGL labels Nov 29, 2022
@jimblandy
Copy link
Member Author

FWIW, the GLenum 0x9245 is UNMASKED_VENDOR_WEBGL in the WEBGL_debug_renderer_info extension.

@jimblandy
Copy link
Member Author

The bug seems to be that wgpu_hal::gles::Adapter::expose calls gl.get_parameter_string(GL_UNMASKED_VENDOR_WEBGL) without actually enabling the WEBGL_debug_renderer_info extension. It merely checks that the extension is present.

@jimblandy
Copy link
Member Author

We should update the wiki when this is fixed.

@jimblandy
Copy link
Member Author

glow has code to enable that extension here, but only for non-Emscripten wasm32.

@jimblandy
Copy link
Member Author

jimblandy commented Nov 30, 2022

It seems to me that it's Emscripten's job to enable these extensions, if it wants to pretend to be GLES (which does not require extensions to be enabled) while actually running on WebGL (which does). I'm not sure we have any next moves here.

@coderedart
Copy link
Contributor

Is there any significance to UNMASKED_VENDOR_WEBGL? since it seems to just be used for info, wgpu can hardcode a fixed string, as a temporary workaround.

Also, is it possible to use https://github.com/emscripten-core/emscripten/blob/main/system/include/emscripten/html5_webgl.h#L61

emscripten_webgl_enable_extension(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context, const char *extension);

to manually enable this extension inside wgpu before calling getString?

@coderedart
Copy link
Contributor

If i add the following lines after making context current ->

unsafe { 
        let ctx = emscripten_webgl_get_current_context();
        emscripten_webgl_enable_extension(ctx, "WEBGL_debug_renderer_info\0".as_ptr() as _);
    }

the example works with no issues.

@coderedart
Copy link
Contributor

So, this error arises because emscripten explicitly avoids enabling this extension at https://github.com/emscripten-core/emscripten/blob/main/src/library_webgl.js#L1135

IDK the main reason they do this, but I am guessing because this extension might not be available in firefox.
https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_debug_renderer_info states

Note: Depending on the privacy settings of the browser, this extension might only be available to privileged contexts or not work at all. In Firefox, if privacy.resistFingerprinting is set to true, this extensions is disabled.

The bug reports in firefox primarily talk about how UNMASKED_RENDERER provides more info about user's hardware than necessary and easily exploited for fingerprinting. https://bugzilla.mozilla.org/show_bug.cgi?id=1722782#c10

@teoxoy
Copy link
Member

teoxoy commented Feb 22, 2023

Did #3519 fix this issue?

@cwfitzgerald
Copy link
Member

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: gles Issues with GLES or WebGL type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants