From e94df11e1b5ea91da726506a975372f84477c456 Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Sun, 29 May 2022 02:34:48 -0400 Subject: [PATCH] Write some unit tests for poll --- wgpu/tests/common/mod.rs | 11 ++++ wgpu/tests/poll.rs | 108 +++++++++++++++++++++++++++++++++++++++ wgpu/tests/root.rs | 1 + 3 files changed, 120 insertions(+) create mode 100644 wgpu/tests/poll.rs diff --git a/wgpu/tests/common/mod.rs b/wgpu/tests/common/mod.rs index a98de71ac6a..10cbb05d5de 100644 --- a/wgpu/tests/common/mod.rs +++ b/wgpu/tests/common/mod.rs @@ -121,6 +121,17 @@ impl TestParameters { self } + /// Mark the test as always failing and needing to be skipped, equivilant to specific_failure(None, None, None) + pub fn skip(mut self) -> Self { + self.failures.push(FailureCase { + backends: None, + vendor: None, + adapter: None, + skip: false, + }); + self + } + /// Mark the test as always failing on a specific backend, equivilant to specific_failure(backend, None, None) pub fn backend_failure(mut self, backends: wgpu::Backends) -> Self { self.failures.push(FailureCase { diff --git a/wgpu/tests/poll.rs b/wgpu/tests/poll.rs new file mode 100644 index 00000000000..5b1b346dbe6 --- /dev/null +++ b/wgpu/tests/poll.rs @@ -0,0 +1,108 @@ +use std::num::NonZeroU64; + +use wgpu::{ + Backends, BindGroupDescriptor, BindGroupEntry, BindGroupLayoutDescriptor, BindGroupLayoutEntry, + BindingResource, BindingType, BufferBindingType, BufferDescriptor, BufferUsages, CommandBuffer, + CommandEncoderDescriptor, ComputePassDescriptor, Maintain, ShaderStages, +}; + +use crate::common::{initialize_test, TestParameters, TestingContext}; + +fn generate_dummy_work(ctx: &TestingContext) -> CommandBuffer { + let buffer = ctx.device.create_buffer(&BufferDescriptor { + label: None, + size: 16, + usage: BufferUsages::UNIFORM, + mapped_at_creation: false, + }); + + let bind_group_layout = ctx + .device + .create_bind_group_layout(&BindGroupLayoutDescriptor { + label: None, + entries: &[BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::COMPUTE, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: Some(NonZeroU64::new(16).unwrap()), + }, + count: None, + }], + }); + + let bind_group = ctx.device.create_bind_group(&BindGroupDescriptor { + label: None, + layout: &bind_group_layout, + entries: &[BindGroupEntry { + binding: 0, + resource: BindingResource::Buffer(buffer.as_entire_buffer_binding()), + }], + }); + + let mut cmd_buf = ctx + .device + .create_command_encoder(&CommandEncoderDescriptor::default()); + + let mut cpass = cmd_buf.begin_compute_pass(&ComputePassDescriptor::default()); + cpass.set_bind_group(0, &bind_group, &[]); + drop(cpass); + + cmd_buf.finish() +} + +#[test] +fn wait() { + initialize_test(TestParameters::default().skip(), |ctx| { + let cmd_buf = generate_dummy_work(&ctx); + + ctx.queue.submit(Some(cmd_buf)); + ctx.device.poll(Maintain::Wait(None)); + }) +} + +#[test] +fn double_wait() { + initialize_test(TestParameters::default().skip(), |ctx| { + let cmd_buf = generate_dummy_work(&ctx); + + ctx.queue.submit(Some(cmd_buf)); + ctx.device.poll(Maintain::Wait(None)); + ctx.device.poll(Maintain::Wait(None)); + }) +} + +#[test] +fn wait_on_submission() { + initialize_test(TestParameters::default().skip(), |ctx| { + let cmd_buf = generate_dummy_work(&ctx); + + let index = ctx.queue.submit(Some(cmd_buf)); + ctx.device.poll(Maintain::Wait(Some(index))); + }) +} + +#[test] +fn double_wait_on_submission() { + initialize_test(TestParameters::default().skip(), |ctx| { + let cmd_buf = generate_dummy_work(&ctx); + + let index = ctx.queue.submit(Some(cmd_buf)); + ctx.device.poll(Maintain::Wait(Some(index))); + ctx.device.poll(Maintain::Wait(Some(index))); + }) +} + +#[test] +fn wait_out_of_order() { + initialize_test(TestParameters::default().skip(), |ctx| { + let cmd_buf1 = generate_dummy_work(&ctx); + let cmd_buf2 = generate_dummy_work(&ctx); + + let index1 = ctx.queue.submit(Some(cmd_buf1)); + let index2 = ctx.queue.submit(Some(cmd_buf2)); + ctx.device.poll(Maintain::Wait(Some(index2))); + ctx.device.poll(Maintain::Wait(Some(index1))); + }) +} diff --git a/wgpu/tests/root.rs b/wgpu/tests/root.rs index 95bf28bf34d..49b7a33872e 100644 --- a/wgpu/tests/root.rs +++ b/wgpu/tests/root.rs @@ -5,5 +5,6 @@ mod clear_texture; mod device; mod example_wgsl; mod instance; +mod poll; mod vertex_indices; mod zero_init_texture_after_discard;