enable debug extension on emscripten (#3519)

* enable debug extension on emscripten

* update changelog

* extract emscripten stuff into a separate module

* use unmasked queries on w-u-u, and only enable extension on emscripten

* fix docs
This commit is contained in:
Red Artist 2023-02-22 11:46:14 +05:30 committed by Connor Fitzgerald
parent 330d112843
commit 1208071e7f
4 changed files with 46 additions and 0 deletions

View File

@ -40,6 +40,13 @@ Bottom level categories:
## Unreleased
## wgpu-0.15.2 (2023-03-08)
### Bug Fixes
#### GLES
- 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)
## wgpu-0.15.1 (2023-02-09)
### Changes

View File

@ -186,10 +186,21 @@ impl super::Adapter {
let extensions = gl.supported_extensions();
let (vendor_const, renderer_const) = if extensions.contains("WEBGL_debug_renderer_info") {
// emscripten doesn't enable "WEBGL_debug_renderer_info" extension by default. so, we do it manually.
// See https://github.com/gfx-rs/wgpu/issues/3245 for context
#[cfg(feature = "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 already enables WEBGL_debug_renderer_info on wasm32-unknown-unknown target by default.
#[cfg(not(feature = "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) };

View File

@ -0,0 +1,26 @@
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;
}
/// Webgl requires extensions to be enabled before using them.
/// This function can be used to enable webgl extension on emscripten target.
///
/// returns true on success
///
/// # Safety:
///
/// - opengl context MUST BE current
/// - extension_name_null_terminated argument must be a valid string with null terminator.
/// - extension must be present. check `glow_context.supported_extensions()`
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
}
}

View File

@ -59,6 +59,8 @@ To address this, we invalidate the vertex buffers based on:
///cbindgen:ignore
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
mod egl;
#[cfg(feature = "emscripten")]
mod emscripten;
#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))]
mod web;