From 4e4545b2b9784c75d0a700fdf3ccf83d5fcd0c2e Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Wed, 23 Feb 2022 16:32:24 -0500 Subject: [PATCH] Make tests properly request their own limits --- wgpu/examples/boids/main.rs | 3 ++- wgpu/examples/hello-compute/tests.rs | 4 ++++ wgpu/tests/common/mod.rs | 20 ++++++++++++++------ wgpu/tests/vertex_indices/mod.rs | 8 ++++---- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/wgpu/examples/boids/main.rs b/wgpu/examples/boids/main.rs index 043d4bc3f97..61cbb344940 100644 --- a/wgpu/examples/boids/main.rs +++ b/wgpu/examples/boids/main.rs @@ -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 }); diff --git a/wgpu/examples/hello-compute/tests.rs b/wgpu/examples/hello-compute/tests.rs index fa518a06cbb..64d49bf15bd 100644 --- a/wgpu/examples/hello-compute/tests.rs +++ b/wgpu/examples/hello-compute/tests.rs @@ -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]; @@ -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]; @@ -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]; @@ -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}; diff --git a/wgpu/tests/common/mod.rs b/wgpu/tests/common/mod.rs index 9e97b47d6bf..0cf7a6a6f6a 100644 --- a/wgpu/tests/common/mod.rs +++ b/wgpu/tests/common/mod.rs @@ -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, } @@ -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(), } } @@ -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. @@ -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 { @@ -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(); @@ -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; } @@ -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 { @@ -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, }; diff --git a/wgpu/tests/vertex_indices/mod.rs b/wgpu/tests/vertex_indices/mod.rs index d75d3e49194..fa85ae62d95 100644 --- a/wgpu/tests/vertex_indices/mod.rs +++ b/wgpu/tests/vertex_indices/mod.rs @@ -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); }) @@ -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| { @@ -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); }) @@ -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| {