Skip to content

Commit

Permalink
Write some unit tests for poll
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed May 29, 2022
1 parent 1436735 commit e94df11
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
11 changes: 11 additions & 0 deletions wgpu/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
108 changes: 108 additions & 0 deletions wgpu/tests/poll.rs
Original file line number Diff line number Diff line change
@@ -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)));
})
}
1 change: 1 addition & 0 deletions wgpu/tests/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit e94df11

Please sign in to comment.