Skip to content

Commit

Permalink
Check for webgl2 validation errors and catch issues (#3296)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald authored Dec 20, 2022
1 parent 5241633 commit 6b6bc69
Show file tree
Hide file tree
Showing 22 changed files with 173 additions and 59 deletions.
3 changes: 3 additions & 0 deletions wgpu/examples/boids/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ fn main() {
framework::run::<Example>("boids");
}

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn boids() {
framework::test::<Example>(framework::FrameworkRefTest {
image_path: "/examples/boids/screenshot.png",
Expand Down
3 changes: 3 additions & 0 deletions wgpu/examples/bunnymark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,10 @@ fn main() {
framework::run::<Example>("bunnymark");
}

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn bunnymark() {
framework::test::<Example>(framework::FrameworkRefTest {
image_path: "/examples/bunnymark/screenshot.png",
Expand Down
3 changes: 3 additions & 0 deletions wgpu/examples/capture/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions wgpu/examples/conservative-raster/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,10 @@ fn main() {
framework::run::<Example>("conservative-raster");
}

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn conservative_raster() {
framework::test::<Example>(framework::FrameworkRefTest {
image_path: "/examples/conservative-raster/screenshot.png",
Expand Down
4 changes: 4 additions & 0 deletions wgpu/examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,10 @@ fn main() {
framework::run::<Example>("cube");
}

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn cube() {
framework::test::<Example>(framework::FrameworkRefTest {
image_path: "/examples/cube/screenshot.png",
Expand All @@ -420,6 +423,7 @@ fn cube() {
}

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn cube_lines() {
framework::test::<Example>(framework::FrameworkRefTest {
image_path: "/examples/cube/screenshot-lines.png",
Expand Down
6 changes: 6 additions & 0 deletions wgpu/examples/hello-compute/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -27,6 +30,7 @@ fn test_compute_1() {
}

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn test_compute_2() {
initialize_test(
TestParameters::default()
Expand All @@ -47,6 +51,7 @@ fn test_compute_2() {
}

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn test_compute_overflow() {
initialize_test(
TestParameters::default()
Expand All @@ -66,6 +71,7 @@ fn test_compute_overflow() {
}

#[test]
// Wasm doesn't support threads
fn test_multithreaded_compute() {
initialize_test(
TestParameters::default()
Expand Down
3 changes: 3 additions & 0 deletions wgpu/examples/mipmap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,10 @@ fn main() {
framework::run::<Example>("mipmap");
}

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn mipmap() {
framework::test::<Example>(framework::FrameworkRefTest {
image_path: "/examples/mipmap/screenshot.png",
Expand Down
3 changes: 3 additions & 0 deletions wgpu/examples/msaa-line/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ fn main() {
framework::run::<Example>("msaa-line");
}

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn msaa_line() {
framework::test::<Example>(framework::FrameworkRefTest {
image_path: "/examples/msaa-line/screenshot.png",
Expand Down
4 changes: 4 additions & 0 deletions wgpu/examples/shadow/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,10 @@ fn main() {
framework::run::<Example>("shadow");
}

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn shadow() {
framework::test::<Example>(framework::FrameworkRefTest {
image_path: "/examples/shadow/screenshot.png",
Expand All @@ -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
Expand Down
13 changes: 12 additions & 1 deletion wgpu/examples/skybox/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,20 +465,29 @@ fn main() {
framework::run::<Skybox>("skybox");
}

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn skybox() {
framework::test::<Skybox>(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::<Skybox>(framework::FrameworkRefTest {
image_path: "/examples/skybox/screenshot-bc1.png",
Expand All @@ -492,6 +501,7 @@ fn skybox_bc1() {
}

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn skybox_etc2() {
framework::test::<Skybox>(framework::FrameworkRefTest {
image_path: "/examples/skybox/screenshot-etc2.png",
Expand All @@ -505,6 +515,7 @@ fn skybox_etc2() {
}

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn skybox_astc() {
framework::test::<Skybox>(framework::FrameworkRefTest {
image_path: "/examples/skybox/screenshot-astc.png",
Expand Down
4 changes: 4 additions & 0 deletions wgpu/examples/texture-arrays/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,10 @@ fn main() {
framework::run::<Example>("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::<Example>(framework::FrameworkRefTest {
image_path: "/examples/texture-arrays/screenshot.png",
Expand All @@ -420,6 +423,7 @@ fn texture_arrays_uniform() {
}

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn texture_arrays_non_uniform() {
framework::test::<Example>(framework::FrameworkRefTest {
image_path: "/examples/texture-arrays/screenshot.png",
Expand Down
3 changes: 3 additions & 0 deletions wgpu/examples/water/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,10 @@ fn main() {
framework::run::<Example>("water");
}

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[test]
#[wasm_bindgen_test::wasm_bindgen_test]
fn water() {
framework::test::<Example>(framework::FrameworkRefTest {
image_path: "/examples/water/screenshot.png",
Expand Down
30 changes: 19 additions & 11 deletions wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<dyn crate::context::QueueWriteBuffer> {
) -> Option<Box<dyn crate::context::QueueWriteBuffer>> {
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
}
}
}

Expand Down
22 changes: 14 additions & 8 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2250,38 +2250,44 @@ 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(
&self,
_queue: &Self::QueueId,
_queue_data: &Self::QueueData,
size: wgt::BufferSize,
) -> Box<dyn QueueWriteBuffer> {
Box::new(WebQueueWriteBuffer(
) -> Option<Box<dyn QueueWriteBuffer>> {
Some(Box::new(WebQueueWriteBuffer(
vec![0; size.get() as usize].into_boxed_slice(),
))
)))
}

fn queue_write_staging_buffer(
Expand Down
12 changes: 6 additions & 6 deletions wgpu/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn QueueWriteBuffer>;
) -> Option<Box<dyn QueueWriteBuffer>>;
fn queue_write_staging_buffer(
&self,
queue: &Self::QueueId,
Expand Down Expand Up @@ -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<dyn QueueWriteBuffer>;
) -> Option<Box<dyn QueueWriteBuffer>>;
fn queue_write_staging_buffer(
&self,
queue: &ObjectId,
Expand Down Expand Up @@ -2785,7 +2785,7 @@ where
buffer_data: &crate::Data,
offset: wgt::BufferAddress,
size: wgt::BufferSize,
) {
) -> Option<()> {
let queue = <T::QueueId>::from(*queue);
let queue_data = downcast_ref(queue_data);
let buffer = <T::BufferId>::from(*buffer);
Expand All @@ -2806,7 +2806,7 @@ where
queue: &ObjectId,
queue_data: &crate::Data,
size: BufferSize,
) -> Box<dyn QueueWriteBuffer> {
) -> Option<Box<dyn QueueWriteBuffer>> {
let queue = <T::QueueId>::from(*queue);
let queue_data = downcast_ref(queue_data);
Context::queue_create_staging_buffer(self, &queue, queue_data, size)
Expand Down
Loading

0 comments on commit 6b6bc69

Please sign in to comment.