diff --git a/wgpu/examples/boids/main.rs b/wgpu/examples/boids/main.rs index a4764cfd45..f56179ae59 100644 --- a/wgpu/examples/boids/main.rs +++ b/wgpu/examples/boids/main.rs @@ -329,7 +329,10 @@ fn main() { framework::run::("boids"); } +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn boids() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/boids/screenshot.png", diff --git a/wgpu/examples/bunnymark/main.rs b/wgpu/examples/bunnymark/main.rs index 1d239b07da..c7383e0296 100644 --- a/wgpu/examples/bunnymark/main.rs +++ b/wgpu/examples/bunnymark/main.rs @@ -357,7 +357,10 @@ fn main() { framework::run::("bunnymark"); } +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn bunnymark() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/bunnymark/screenshot.png", diff --git a/wgpu/examples/capture/main.rs b/wgpu/examples/capture/main.rs index 610a431532..747b361de2 100644 --- a/wgpu/examples/capture/main.rs +++ b/wgpu/examples/capture/main.rs @@ -225,7 +225,10 @@ mod tests { use super::*; use wgpu::BufferView; + wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + #[test] + #[wasm_bindgen_test::wasm_bindgen_test] fn ensure_generated_data_matches_expected() { assert_generated_data_matches_expected(); } diff --git a/wgpu/examples/conservative-raster/main.rs b/wgpu/examples/conservative-raster/main.rs index 7703c22466..2fc4e98676 100644 --- a/wgpu/examples/conservative-raster/main.rs +++ b/wgpu/examples/conservative-raster/main.rs @@ -314,7 +314,10 @@ fn main() { framework::run::("conservative-raster"); } +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn conservative_raster() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/conservative-raster/screenshot.png", diff --git a/wgpu/examples/cube/main.rs b/wgpu/examples/cube/main.rs index 5f0ffb9dcf..d029f7035e 100644 --- a/wgpu/examples/cube/main.rs +++ b/wgpu/examples/cube/main.rs @@ -406,7 +406,10 @@ fn main() { framework::run::("cube"); } +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn cube() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/cube/screenshot.png", @@ -420,6 +423,7 @@ fn cube() { } #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn cube_lines() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/cube/screenshot-lines.png", diff --git a/wgpu/examples/hello-compute/tests.rs b/wgpu/examples/hello-compute/tests.rs index 5ed49b60b2..52e62d1c81 100644 --- a/wgpu/examples/hello-compute/tests.rs +++ b/wgpu/examples/hello-compute/tests.rs @@ -6,7 +6,10 @@ use std::sync::Arc; use super::*; use common::{initialize_test, TestParameters}; +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn test_compute_1() { initialize_test( TestParameters::default() @@ -27,6 +30,7 @@ fn test_compute_1() { } #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn test_compute_2() { initialize_test( TestParameters::default() @@ -47,6 +51,7 @@ fn test_compute_2() { } #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn test_compute_overflow() { initialize_test( TestParameters::default() @@ -66,6 +71,7 @@ fn test_compute_overflow() { } #[test] +// Wasm doesn't support threads fn test_multithreaded_compute() { initialize_test( TestParameters::default() diff --git a/wgpu/examples/mipmap/main.rs b/wgpu/examples/mipmap/main.rs index 5e62e35c06..f1cac82e9c 100644 --- a/wgpu/examples/mipmap/main.rs +++ b/wgpu/examples/mipmap/main.rs @@ -487,7 +487,10 @@ fn main() { framework::run::("mipmap"); } +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn mipmap() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/mipmap/screenshot.png", diff --git a/wgpu/examples/msaa-line/main.rs b/wgpu/examples/msaa-line/main.rs index b39c144877..5817b13ced 100644 --- a/wgpu/examples/msaa-line/main.rs +++ b/wgpu/examples/msaa-line/main.rs @@ -310,7 +310,10 @@ fn main() { framework::run::("msaa-line"); } +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn msaa_line() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/msaa-line/screenshot.png", diff --git a/wgpu/examples/shadow/main.rs b/wgpu/examples/shadow/main.rs index d2eba66c30..dd215dfddb 100644 --- a/wgpu/examples/shadow/main.rs +++ b/wgpu/examples/shadow/main.rs @@ -841,7 +841,10 @@ fn main() { framework::run::("shadow"); } +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn shadow() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/shadow/screenshot.png", @@ -850,6 +853,7 @@ fn shadow() { optional_features: wgpu::Features::default(), base_test_parameters: framework::test_common::TestParameters::default() .downlevel_flags(wgpu::DownlevelFlags::COMPARISON_SAMPLERS) + .specific_failure(Some(wgpu::Backends::GL), None, Some("ANGLE"), false) // rpi4 on VK doesn't work: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3916 .specific_failure(Some(wgpu::Backends::VULKAN), None, Some("V3D"), false) // llvmpipe versions in CI are flaky: https://github.com/gfx-rs/wgpu/issues/2594 diff --git a/wgpu/examples/skybox/main.rs b/wgpu/examples/skybox/main.rs index f1cd423a47..987a4ebaa9 100644 --- a/wgpu/examples/skybox/main.rs +++ b/wgpu/examples/skybox/main.rs @@ -465,20 +465,29 @@ fn main() { framework::run::("skybox"); } +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn skybox() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/skybox/screenshot.png", width: 1024, height: 768, optional_features: wgpu::Features::default(), - base_test_parameters: framework::test_common::TestParameters::default(), + base_test_parameters: framework::test_common::TestParameters::default().specific_failure( + Some(wgpu::Backends::GL), + None, + Some("ANGLE"), + false, + ), tolerance: 3, max_outliers: 207, // bounded by swiftshader }); } #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn skybox_bc1() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/skybox/screenshot-bc1.png", @@ -492,6 +501,7 @@ fn skybox_bc1() { } #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn skybox_etc2() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/skybox/screenshot-etc2.png", @@ -505,6 +515,7 @@ fn skybox_etc2() { } #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn skybox_astc() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/skybox/screenshot-astc.png", diff --git a/wgpu/examples/texture-arrays/main.rs b/wgpu/examples/texture-arrays/main.rs index 687a0258f7..89093b6400 100644 --- a/wgpu/examples/texture-arrays/main.rs +++ b/wgpu/examples/texture-arrays/main.rs @@ -406,7 +406,10 @@ fn main() { framework::run::("texture-arrays"); } +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn texture_arrays_uniform() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/texture-arrays/screenshot.png", @@ -420,6 +423,7 @@ fn texture_arrays_uniform() { } #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn texture_arrays_non_uniform() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/texture-arrays/screenshot.png", diff --git a/wgpu/examples/water/main.rs b/wgpu/examples/water/main.rs index aa785c6ec0..3eb08940b9 100644 --- a/wgpu/examples/water/main.rs +++ b/wgpu/examples/water/main.rs @@ -818,7 +818,10 @@ fn main() { framework::run::("water"); } +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + #[test] +#[wasm_bindgen_test::wasm_bindgen_test] fn water() { framework::test::(framework::FrameworkRefTest { image_path: "/examples/water/screenshot.png", diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index ebdf41d61b..d9632843d4 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -2072,7 +2072,7 @@ impl crate::Context for Context { fn queue_write_buffer( &self, queue: &Self::QueueId, - _queue_data: &Self::QueueData, + queue_data: &Self::QueueData, buffer: &Self::BufferId, _buffer_data: &Self::BufferData, offset: wgt::BufferAddress, @@ -2083,46 +2083,54 @@ impl crate::Context for Context { *queue => global.queue_write_buffer(*queue, *buffer, offset, data) ) { Ok(()) => (), - Err(err) => self.handle_error_fatal(err, "Queue::write_buffer"), + Err(err) => { + self.handle_error_nolabel(&queue_data.error_sink, err, "Queue::write_buffer") + } } } fn queue_validate_write_buffer( &self, queue: &Self::QueueId, - _queue_data: &Self::QueueData, + queue_data: &Self::QueueData, buffer: &Self::BufferId, _buffer_data: &Self::BufferData, offset: wgt::BufferAddress, size: wgt::BufferSize, - ) { + ) -> Option<()> { let global = &self.0; match wgc::gfx_select!( *queue => global.queue_validate_write_buffer(*queue, *buffer, offset, size.get()) ) { - Ok(()) => (), - Err(err) => self.handle_error_fatal(err, "Queue::write_buffer_with"), + Ok(()) => Some(()), + Err(err) => { + self.handle_error_nolabel(&queue_data.error_sink, err, "Queue::write_buffer_with"); + None + } } } fn queue_create_staging_buffer( &self, queue: &Self::QueueId, - _queue_data: &Self::QueueData, + queue_data: &Self::QueueData, size: wgt::BufferSize, - ) -> Box { + ) -> Option> { let global = &self.0; match wgc::gfx_select!( *queue => global.queue_create_staging_buffer(*queue, size, ()) ) { - Ok((buffer_id, ptr)) => Box::new(QueueWriteBuffer { + Ok((buffer_id, ptr)) => Some(Box::new(QueueWriteBuffer { buffer_id, mapping: BufferMappedRange { ptr, size: size.get() as usize, }, - }), - Err(err) => self.handle_error_fatal(err, "Queue::write_buffer_with"), + })), + Err(err) => { + self.handle_error_nolabel(&queue_data.error_sink, err, "Queue::write_buffer_with"); + None + } } } diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index bd490cd1a6..8b55f4fc6b 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -2250,27 +2250,33 @@ impl crate::context::Context for Context { _buffer_data: &Self::BufferData, offset: wgt::BufferAddress, size: wgt::BufferSize, - ) { + ) -> Option<()> { let usage = wgt::BufferUsages::from_bits_truncate(buffer.0.usage()); + // TODO: actually send this down the error scope if !usage.contains(wgt::BufferUsages::COPY_DST) { - panic!("Destination buffer is missing the `COPY_DST` usage flag"); + log::error!("Destination buffer is missing the `COPY_DST` usage flag"); + return None; } let write_size = u64::from(size); if write_size % wgt::COPY_BUFFER_ALIGNMENT != 0 { - panic!( + log::error!( "Copy size {} does not respect `COPY_BUFFER_ALIGNMENT`", size ); + return None; } if offset % wgt::COPY_BUFFER_ALIGNMENT != 0 { - panic!( + log::error!( "Buffer offset {} is not aligned to block size or `COPY_BUFFER_ALIGNMENT`", offset ); + return None; } if write_size + offset > buffer.0.size() as u64 { - panic!("copy of {}..{} would end up overrunning the bounds of the destination buffer of size {}", offset, offset + write_size, buffer.0.size()); + log::error!("copy of {}..{} would end up overrunning the bounds of the destination buffer of size {}", offset, offset + write_size, buffer.0.size()); + return None; } + Some(()) } fn queue_create_staging_buffer( @@ -2278,10 +2284,10 @@ impl crate::context::Context for Context { _queue: &Self::QueueId, _queue_data: &Self::QueueData, size: wgt::BufferSize, - ) -> Box { - Box::new(WebQueueWriteBuffer( + ) -> Option> { + Some(Box::new(WebQueueWriteBuffer( vec![0; size.get() as usize].into_boxed_slice(), - )) + ))) } fn queue_write_staging_buffer( diff --git a/wgpu/src/context.rs b/wgpu/src/context.rs index cbdb95eb09..410ed2c0b7 100644 --- a/wgpu/src/context.rs +++ b/wgpu/src/context.rs @@ -538,13 +538,13 @@ pub trait Context: Debug + Send + Sized + Sync { buffer_data: &Self::BufferData, offset: wgt::BufferAddress, size: wgt::BufferSize, - ); + ) -> Option<()>; fn queue_create_staging_buffer( &self, queue: &Self::QueueId, queue_data: &Self::QueueData, size: BufferSize, - ) -> Box; + ) -> Option>; fn queue_write_staging_buffer( &self, queue: &Self::QueueId, @@ -1438,13 +1438,13 @@ pub(crate) trait DynContext: Debug + Send + Sync { buffer_data: &crate::Data, offset: wgt::BufferAddress, size: wgt::BufferSize, - ); + ) -> Option<()>; fn queue_create_staging_buffer( &self, queue: &ObjectId, queue_data: &crate::Data, size: BufferSize, - ) -> Box; + ) -> Option>; fn queue_write_staging_buffer( &self, queue: &ObjectId, @@ -2785,7 +2785,7 @@ where buffer_data: &crate::Data, offset: wgt::BufferAddress, size: wgt::BufferSize, - ) { + ) -> Option<()> { let queue = ::from(*queue); let queue_data = downcast_ref(queue_data); let buffer = ::from(*buffer); @@ -2806,7 +2806,7 @@ where queue: &ObjectId, queue_data: &crate::Data, size: BufferSize, - ) -> Box { + ) -> Option> { let queue = ::from(*queue); let queue_data = downcast_ref(queue_data); Context::queue_create_staging_buffer(self, &queue, queue_data, size) diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 38f32e2668..43e05e6da6 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -59,7 +59,7 @@ static_assertions::assert_impl_all!(ErrorFilter: Send, Sync); type C = dyn DynContext; type Data = dyn Any + Send + Sync; -/// Context for all other wgpu objects. Instance of wgpu. +/// Context for all other wgpu objects. Instan ce of wgpu. /// /// This is the first thing you create when using wgpu. /// Its primary use is to create [`Adapter`]s and [`Surface`]s. @@ -3734,7 +3734,7 @@ impl Queue { buffer: &'a Buffer, offset: BufferAddress, size: BufferSize, - ) -> QueueWriteBufferView<'a> { + ) -> Option> { DynContext::queue_validate_write_buffer( &*self.context, &self.id, @@ -3743,19 +3743,19 @@ impl Queue { buffer.data.as_ref(), offset, size, - ); + )?; let staging_buffer = DynContext::queue_create_staging_buffer( &*self.context, &self.id, self.data.as_ref(), size, - ); - QueueWriteBufferView { + )?; + Some(QueueWriteBufferView { queue: self, buffer, offset, inner: staging_buffer, - } + }) } /// Schedule a write of some data into a texture. diff --git a/wgpu/tests/buffer_copy.rs b/wgpu/tests/buffer_copy.rs index 56d584edbc..98baf2c78b 100644 --- a/wgpu/tests/buffer_copy.rs +++ b/wgpu/tests/buffer_copy.rs @@ -1,21 +1,20 @@ //! Tests for buffer copy validation. +use wasm_bindgen_test::wasm_bindgen_test; use wgt::BufferAddress; -use crate::common::{initialize_test, TestParameters}; +use crate::common::{fail_if, initialize_test, TestParameters}; #[test] +#[wasm_bindgen_test] fn copy_alignment() { - fn try_copy(offset: BufferAddress, size: BufferAddress, should_panic: bool) { - let mut parameters = TestParameters::default(); - if should_panic { - parameters = parameters.failure(); - } - - initialize_test(parameters, |ctx| { + fn try_copy(offset: BufferAddress, size: BufferAddress, should_fail: bool) { + initialize_test(TestParameters::default(), |ctx| { let buffer = ctx.device.create_buffer(&BUFFER_DESCRIPTOR); let data = vec![255; size as usize]; - ctx.queue.write_buffer(&buffer, offset, &data); + fail_if(&ctx.device, should_fail, || { + ctx.queue.write_buffer(&buffer, offset, &data) + }); }); } diff --git a/wgpu/tests/clear_texture.rs b/wgpu/tests/clear_texture.rs index 0e8a75f3b0..70c42ba433 100644 --- a/wgpu/tests/clear_texture.rs +++ b/wgpu/tests/clear_texture.rs @@ -307,9 +307,12 @@ fn clear_texture_tests( } #[test] +#[wasm_bindgen_test] fn clear_texture_2d_uncompressed() { initialize_test( - TestParameters::default().features(wgpu::Features::CLEAR_TEXTURE), + TestParameters::default() + .webgl2_failure() + .features(wgpu::Features::CLEAR_TEXTURE), |ctx| { clear_texture_tests(&ctx, TEXTURE_FORMATS_UNCOMPRESSED, true, true); clear_texture_tests(&ctx, TEXTURE_FORMATS_DEPTH, false, false); diff --git a/wgpu/tests/common/image.rs b/wgpu/tests/common/image.rs index 69e1f986f9..fc80ac8eac 100644 --- a/wgpu/tests/common/image.rs +++ b/wgpu/tests/common/image.rs @@ -1,7 +1,6 @@ use std::{ ffi::{OsStr, OsString}, - fs::File, - io::{BufWriter, Cursor}, + io, path::Path, str::FromStr, }; @@ -18,7 +17,7 @@ fn read_png(path: impl AsRef, width: u32, height: u32) -> Option> return None; } }; - let decoder = png::Decoder::new(Cursor::new(data)); + let decoder = png::Decoder::new(io::Cursor::new(data)); let mut reader = decoder.read_info().ok()?; let mut buffer = vec![0; reader.output_buffer_size()]; @@ -43,6 +42,7 @@ fn read_png(path: impl AsRef, width: u32, height: u32) -> Option> Some(buffer) } +#[allow(unused_variables)] fn write_png( path: impl AsRef, width: u32, @@ -50,15 +50,18 @@ fn write_png( data: &[u8], compression: png::Compression, ) { - let file = BufWriter::new(File::create(path).unwrap()); + #[cfg(not(target_arch = "wasm32"))] + { + let file = io::BufWriter::new(std::fs::File::create(path).unwrap()); - let mut encoder = png::Encoder::new(file, width, height); - encoder.set_color(png::ColorType::Rgba); - encoder.set_depth(png::BitDepth::Eight); - encoder.set_compression(compression); - let mut writer = encoder.write_header().unwrap(); + let mut encoder = png::Encoder::new(file, width, height); + encoder.set_color(png::ColorType::Rgba); + encoder.set_depth(png::BitDepth::Eight); + encoder.set_compression(compression); + let mut writer = encoder.write_header().unwrap(); - writer.write_image_data(data).unwrap(); + writer.write_image_data(data).unwrap(); + } } fn calc_difference(lhs: u8, rhs: u8) -> u8 { diff --git a/wgpu/tests/common/isolation.rs b/wgpu/tests/common/isolation.rs index e4c7b6e560..d99f425088 100644 --- a/wgpu/tests/common/isolation.rs +++ b/wgpu/tests/common/isolation.rs @@ -27,7 +27,10 @@ pub struct OneTestPerProcessGuard(()); impl OneTestPerProcessGuard { pub fn new() -> Self { let other_tests_in_flight = TEST_ACTIVE_IN_PROCESS.swap(true, Ordering::SeqCst); - if other_tests_in_flight { + + // We never abort if we're on wasm. Wasm tests are inherently single threaded, and panics cannot + // unwind the stack and trigger all the guards, so we don't actually need to check. + if other_tests_in_flight && !cfg!(target_arch = "wasm32") { log::error!("{}", OTHER_TEST_IN_PROGRESS_ERROR); // Hard exit to call attention to the error std::process::abort(); diff --git a/wgpu/tests/common/mod.rs b/wgpu/tests/common/mod.rs index 37fafed043..cdcf8f94ea 100644 --- a/wgpu/tests/common/mod.rs +++ b/wgpu/tests/common/mod.rs @@ -145,6 +145,20 @@ impl TestParameters { self } + /// Mark the test as always failing on WebGL. Because limited ability of wasm to recover from errors, we need to wholesale + /// skip the test if it's not supported. + pub fn webgl2_failure(mut self) -> Self { + let _ = &mut self; + #[cfg(target_arch = "wasm32")] + self.failures.push(FailureCase { + backends: Some(wgpu::Backends::GL), + vendor: None, + adapter: None, + skip: true, + }); + self + } + /// Determines if a test should fail under a particular set of conditions. If any of these are None, that means that it will match anything in that field. /// /// ex. @@ -178,7 +192,7 @@ pub fn initialize_test(parameters: TestParameters, test_function: impl FnOnce(Te let _test_guard = isolation::OneTestPerProcessGuard::new(); - let (adapter, _) = initialize_adapter(); + let (adapter, _surface_guard) = initialize_adapter(); let adapter_info = adapter.get_info(); let adapter_lowercase_name = adapter_info.name.to_lowercase(); @@ -283,7 +297,7 @@ pub fn initialize_test(parameters: TestParameters, test_function: impl FnOnce(Te if #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] { let canary_set = hal::VALIDATION_CANARY.get_and_reset(); } else { - let canary_set = false; + let canary_set = _surface_guard.check_for_unreported_errors(); } ); @@ -319,10 +333,12 @@ pub fn initialize_test(parameters: TestParameters, test_function: impl FnOnce(Te fn initialize_adapter() -> (Adapter, SurfaceGuard) { let backend_bits = wgpu::util::backend_bits_from_env().unwrap_or_else(Backends::all); let instance = Instance::new(backend_bits); + let surface_guard; let compatible_surface; #[cfg(not(all(target_arch = "wasm32", feature = "webgl")))] { + surface_guard = SurfaceGuard {}; compatible_surface = None; } #[cfg(all(target_arch = "wasm32", feature = "webgl"))] @@ -334,6 +350,8 @@ fn initialize_adapter() -> (Adapter, SurfaceGuard) { .create_surface_from_canvas(&canvas) .expect("could not create surface from canvas"); + surface_guard = SurfaceGuard { canvas }; + compatible_surface = Some(surface); } @@ -345,10 +363,34 @@ fn initialize_adapter() -> (Adapter, SurfaceGuard) { )) .expect("could not find suitable adapter on the system"); - (adapter, SurfaceGuard) + (adapter, surface_guard) } -struct SurfaceGuard; +struct SurfaceGuard { + #[cfg(all(target_arch = "wasm32", feature = "webgl"))] + canvas: web_sys::HtmlCanvasElement, +} + +impl SurfaceGuard { + fn check_for_unreported_errors(&self) -> bool { + cfg_if::cfg_if! { + if #[cfg(all(target_arch = "wasm32", feature = "webgl"))] { + use wasm_bindgen::JsCast; + + self.canvas + .get_context("webgl2") + .unwrap() + .unwrap() + .dyn_into::() + .unwrap() + .get_error() + != web_sys::WebGl2RenderingContext::NO_ERROR + } else { + false + } + } + } +} #[cfg(all(target_arch = "wasm32", feature = "webgl"))] impl Drop for SurfaceGuard { diff --git a/wgpu/tests/zero_init_texture_after_discard.rs b/wgpu/tests/zero_init_texture_after_discard.rs index 3c584eb7e4..751ae2aa77 100644 --- a/wgpu/tests/zero_init_texture_after_discard.rs +++ b/wgpu/tests/zero_init_texture_after_discard.rs @@ -7,7 +7,7 @@ use wasm_bindgen_test::*; #[test] #[wasm_bindgen_test] fn discarding_color_target_resets_texture_init_state_check_visible_on_copy_after_submit() { - initialize_test(TestParameters::default(), |ctx| { + initialize_test(TestParameters::default().webgl2_failure(), |ctx| { let (texture, readback_buffer) = create_white_texture_and_readback_buffer(&ctx, wgpu::TextureFormat::Rgba8UnormSrgb); { @@ -43,7 +43,7 @@ fn discarding_color_target_resets_texture_init_state_check_visible_on_copy_after #[test] #[wasm_bindgen_test] fn discarding_color_target_resets_texture_init_state_check_visible_on_copy_in_same_encoder() { - initialize_test(TestParameters::default(), |ctx| { + initialize_test(TestParameters::default().webgl2_failure(), |ctx| { let (texture, readback_buffer) = create_white_texture_and_readback_buffer(&ctx, wgpu::TextureFormat::Rgba8UnormSrgb); {