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

enable debug extension on emscripten #3519

Merged
merged 5 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ By @teoxoy in [#3436](https://github.com/gfx-rs/wgpu/pull/3436)
#### GLES

- [gles] fix: Set FORCE_POINT_SIZE if it is vertex shader with mesh consist of point list. By @REASY in [3440](https://github.com/gfx-rs/wgpu/pull/3440)
- [gles] fix: enable `WEBGL_debug_renderer_info` before querying unmasked vendor/renderer to avoid crashing on emscripten in [#3519](https://github.com/gfx-rs/wgpu/pull/3519)

#### General

Expand Down
10 changes: 10 additions & 0 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,20 @@ impl super::Adapter {
let extensions = gl.supported_extensions();

let (vendor_const, renderer_const) = if extensions.contains("WEBGL_debug_renderer_info") {
// context must be current
coderedart marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(target_os = "emscripten")]
if unsafe { super::emscripten::enable_extension("WEBGL_debug_renderer_info\0") } {
(GL_UNMASKED_VENDOR_WEBGL, GL_UNMASKED_RENDERER_WEBGL)
} else {
(glow::VENDOR, glow::RENDERER)
}
// glow enables WEBGL_debug_renderer_info on w-u-u target.
coderedart marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(not(target_os = "emscripten"))]
(GL_UNMASKED_VENDOR_WEBGL, GL_UNMASKED_RENDERER_WEBGL)
} else {
(glow::VENDOR, glow::RENDERER)
};

let (vendor, renderer) = {
let vendor = unsafe { gl.get_parameter_string(vendor_const) };
let renderer = unsafe { gl.get_parameter_string(renderer_const) };
Expand Down
22 changes: 22 additions & 0 deletions wgpu-hal/src/gles/emscripten.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
extern "C" {
/// returns 1 if success. 0 if failure. extension name must be null terminated
fn emscripten_webgl_enable_extension(
context: std::ffi::c_int,
extension: *const std::ffi::c_char,
) -> std::ffi::c_int;
fn emscripten_webgl_get_current_context() -> std::ffi::c_int;
}
/// if we have debug extension and if we can enable it -> use unmasked vendor/renderer
coderedart marked this conversation as resolved.
Show resolved Hide resolved
/// https://github.com/gfx-rs/wgpu/issues/3245
coderedart marked this conversation as resolved.
Show resolved Hide resolved
/// returns true on success
/// # Safety:
/// opengl context MUST BE current
/// extension_name_null_terminated argument must be a valid string with null terminator.
coderedart marked this conversation as resolved.
Show resolved Hide resolved
pub unsafe fn enable_extension(extension_name_null_terminated: &str) -> bool {
unsafe {
emscripten_webgl_enable_extension(
emscripten_webgl_get_current_context(),
extension_name_null_terminated.as_ptr() as _,
) == 1
}
}
2 changes: 2 additions & 0 deletions wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ To address this, we invalidate the vertex buffers based on:
///cbindgen:ignore
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))]
mod egl;
#[cfg(target_os = "emscripten")]
mod emscripten;
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
mod web;

Expand Down