Skip to content

Commit

Permalink
Make tests properly request their own limits
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Feb 23, 2022
1 parent cd8ddcd commit 4e4545b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
3 changes: 2 additions & 1 deletion wgpu/examples/boids/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ fn boids() {
height: 768,
optional_features: wgpu::Features::default(),
base_test_parameters: framework::test_common::TestParameters::default()
.downlevel_flags(wgpu::DownlevelFlags::COMPUTE_SHADERS),
.downlevel_flags(wgpu::DownlevelFlags::COMPUTE_SHADERS)
.limits(wgpu::Limits::downlevel_defaults()),
tolerance: 0,
max_outliers: 2500, // Currently bounded by WARP
});
Expand Down
4 changes: 4 additions & 0 deletions wgpu/examples/hello-compute/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fn test_compute_1() {
initialize_test(
TestParameters::default()
.downlevel_flags(wgpu::DownlevelFlags::COMPUTE_SHADERS)
.limits(wgpu::Limits::downlevel_defaults())
.specific_failure(None, None, Some("V3D"), true),
|ctx| {
let input = &[1, 2, 3, 4];
Expand All @@ -30,6 +31,7 @@ fn test_compute_2() {
initialize_test(
TestParameters::default()
.downlevel_flags(wgpu::DownlevelFlags::COMPUTE_SHADERS)
.limits(wgpu::Limits::downlevel_defaults())
.specific_failure(None, None, Some("V3D"), true),
|ctx| {
let input = &[5, 23, 10, 9];
Expand All @@ -49,6 +51,7 @@ fn test_compute_overflow() {
initialize_test(
TestParameters::default()
.downlevel_flags(wgpu::DownlevelFlags::COMPUTE_SHADERS)
.limits(wgpu::Limits::downlevel_defaults())
.specific_failure(None, None, Some("V3D"), true),
|ctx| {
let input = &[77031, 837799, 8400511, 63728127];
Expand All @@ -67,6 +70,7 @@ fn test_multithreaded_compute() {
initialize_test(
TestParameters::default()
.downlevel_flags(wgpu::DownlevelFlags::COMPUTE_SHADERS)
.limits(wgpu::Limits::downlevel_defaults())
.specific_failure(None, None, Some("V3D"), true),
|ctx| {
use std::{sync::mpsc, thread, time::Duration};
Expand Down
20 changes: 14 additions & 6 deletions wgpu/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub struct FailureCase {
pub struct TestParameters {
pub required_features: Features,
pub required_downlevel_properties: DownlevelCapabilities,
pub required_limits: Limits,
// Backends where test should fail.
pub failures: Vec<FailureCase>,
}
Expand All @@ -69,6 +70,7 @@ impl Default for TestParameters {
Self {
required_features: Features::empty(),
required_downlevel_properties: lowest_downlevel_properties(),
required_limits: Limits::downlevel_webgl2_defaults(),
failures: Vec::new(),
}
}
Expand All @@ -85,9 +87,10 @@ bitflags::bitflags! {

// Builder pattern to make it easier
impl TestParameters {
/// Set of common features that most tests require.
pub fn test_features(self) -> Self {
/// Set of common features that most internal tests require for readback.
pub fn test_features_limits(self) -> Self {
self.features(Features::MAPPABLE_PRIMARY_BUFFERS | Features::VERTEX_WRITABLE_STORAGE)
.limits(wgpu::Limits::downlevel_defaults())
}

/// Set the list of features this test requires.
Expand All @@ -101,6 +104,12 @@ impl TestParameters {
self
}

/// Set the limits needed for the test.
pub fn limits(mut self, limits: Limits) -> Self {
self.required_limits = limits;
self
}

/// Mark the test as always failing, equivilant to specific_failure(None, None, None)
pub fn failure(mut self) -> Self {
self.failures.push(FailureCase {
Expand Down Expand Up @@ -159,7 +168,6 @@ pub fn initialize_test(parameters: TestParameters, test_function: impl FnOnce(Te
))
.expect("could not find sutable adapter on the system");

let required_limits = Limits::downlevel_webgl2_defaults();
let adapter_info = adapter.get_info();
let adapter_lowercase_name = adapter_info.name.to_lowercase();
let adapter_features = adapter.features();
Expand All @@ -172,7 +180,7 @@ pub fn initialize_test(parameters: TestParameters, test_function: impl FnOnce(Te
return;
}

if adapter_limits < required_limits {
if !parameters.required_limits.check_limits(&adapter_limits) {
println!("TEST SKIPPED: LIMIT TOO LOW");
return;
}
Expand Down Expand Up @@ -200,7 +208,7 @@ pub fn initialize_test(parameters: TestParameters, test_function: impl FnOnce(Te
let (device, queue) = pollster::block_on(initialize_device(
&adapter,
parameters.required_features,
required_limits.clone(),
parameters.required_limits.clone(),
));

let context = TestingContext {
Expand All @@ -209,7 +217,7 @@ pub fn initialize_test(parameters: TestParameters, test_function: impl FnOnce(Te
adapter_downlevel_capabilities,
device,
device_features: parameters.required_features,
device_limits: required_limits,
device_limits: parameters.required_limits,
queue,
};

Expand Down
8 changes: 4 additions & 4 deletions wgpu/tests/vertex_indices/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn pulling_common(

#[test]
fn draw() {
initialize_test(TestParameters::default().test_features(), |ctx| {
initialize_test(TestParameters::default().test_features_limits(), |ctx| {
pulling_common(ctx, &[0, 1, 2, 3, 4, 5], |cmb| {
cmb.draw(0..6, 0..1);
})
Expand All @@ -143,7 +143,7 @@ fn draw() {
fn draw_vertex_offset() {
initialize_test(
TestParameters::default()
.test_features()
.test_features_limits()
.backend_failure(wgpu::Backends::DX11),
|ctx| {
pulling_common(ctx, &[0, 1, 2, 3, 4, 5], |cmb| {
Expand All @@ -156,7 +156,7 @@ fn draw_vertex_offset() {

#[test]
fn draw_instanced() {
initialize_test(TestParameters::default().test_features(), |ctx| {
initialize_test(TestParameters::default().test_features_limits(), |ctx| {
pulling_common(ctx, &[0, 1, 2, 3, 4, 5], |cmb| {
cmb.draw(0..3, 0..2);
})
Expand All @@ -167,7 +167,7 @@ fn draw_instanced() {
fn draw_instanced_offset() {
initialize_test(
TestParameters::default()
.test_features()
.test_features_limits()
.backend_failure(wgpu::Backends::DX11),
|ctx| {
pulling_common(ctx, &[0, 1, 2, 3, 4, 5], |cmb| {
Expand Down

0 comments on commit 4e4545b

Please sign in to comment.