1use arrayvec::ArrayVec;
2use wgpu::{DownlevelCapabilities, DownlevelFlags, Features, InstanceFlags, Limits};
3
4use crate::{
5 report::AdapterReport, FailureApplicationReasons, FailureBehavior, FailureCase,
6 GpuTestConfiguration,
7};
8
9const LOWEST_DOWNLEVEL_PROPERTIES: wgpu::DownlevelCapabilities = DownlevelCapabilities {
10 flags: wgpu::DownlevelFlags::empty(),
11 limits: wgpu::DownlevelLimits {},
12 shader_model: wgpu::ShaderModel::Sm2,
13};
14
15#[derive(Clone)]
17pub struct TestParameters {
18 pub required_features: Features,
19 pub required_downlevel_caps: DownlevelCapabilities,
20 pub required_limits: Limits,
21
22 pub required_instance_flags: InstanceFlags,
23
24 pub force_fxc: bool,
28
29 pub skips: Vec<FailureCase>,
31
32 pub failures: Vec<FailureCase>,
34}
35
36impl Default for TestParameters {
37 fn default() -> Self {
38 Self {
39 required_features: Features::empty(),
40 required_downlevel_caps: LOWEST_DOWNLEVEL_PROPERTIES,
41 required_limits: Limits::downlevel_webgl2_defaults(),
42 required_instance_flags: InstanceFlags::empty(),
43 force_fxc: false,
44 skips: vec![FailureCase::backend(wgpu::Backends::NOOP)],
47 failures: Vec::new(),
48 }
49 }
50}
51
52impl TestParameters {
54 pub fn test_features_limits(self) -> Self {
56 self.downlevel_flags(DownlevelFlags::COMPUTE_SHADERS)
57 .limits(wgpu::Limits::downlevel_defaults())
58 }
59
60 pub fn features(mut self, features: Features) -> Self {
62 self.required_features |= features;
63 self
64 }
65
66 pub fn downlevel_flags(mut self, downlevel_flags: DownlevelFlags) -> Self {
67 self.required_downlevel_caps.flags |= downlevel_flags;
68 self
69 }
70
71 pub fn limits(mut self, limits: Limits) -> Self {
73 self.required_limits = limits;
74 self
75 }
76
77 pub fn instance_flags(mut self, instance_flags: InstanceFlags) -> Self {
79 self.required_instance_flags |= instance_flags;
80 self
81 }
82
83 pub fn force_fxc(mut self, force_fxc: bool) -> Self {
84 self.force_fxc = force_fxc;
85 self
86 }
87
88 pub fn expect_fail(mut self, when: FailureCase) -> Self {
90 self.failures.push(when);
91 self
92 }
93
94 pub fn skip(mut self, when: FailureCase) -> Self {
96 self.skips.push(when);
97 self
98 }
99
100 pub fn enable_noop(mut self) -> Self {
105 self.skips
106 .retain(|case| *case != FailureCase::backend(wgpu::Backends::NOOP));
107 self
108 }
109}
110
111pub struct TestInfo {
113 pub skip: bool,
114 pub failure_application_reasons: FailureApplicationReasons,
115 pub failures: Vec<FailureCase>,
116 pub running_msg: String,
117}
118
119impl TestInfo {
120 pub(crate) fn from_configuration(test: &GpuTestConfiguration, adapter: &AdapterReport) -> Self {
121 let mut unsupported_reasons: ArrayVec<_, 4> = ArrayVec::new();
123 let missing_features = test.params.required_features - adapter.features;
124 if !missing_features.is_empty() {
125 unsupported_reasons.push("Features");
126 }
127
128 if !test.params.required_limits.check_limits(&adapter.limits) {
129 unsupported_reasons.push("Limits");
130 }
131
132 let missing_downlevel_flags =
133 test.params.required_downlevel_caps.flags - adapter.downlevel_caps.flags;
134 if !missing_downlevel_flags.is_empty() {
135 unsupported_reasons.push("Downlevel Flags");
136 }
137
138 if test.params.required_downlevel_caps.shader_model > adapter.downlevel_caps.shader_model {
139 unsupported_reasons.push("Shader Model");
140 }
141
142 let adapter_lowercase_info = wgpu::AdapterInfo {
145 name: adapter.info.name.to_lowercase(),
146 driver: adapter.info.driver.to_lowercase(),
147 ..adapter.info.clone()
148 };
149
150 let skip_application_reason = test
152 .params
153 .skips
154 .iter()
155 .find_map(|case| case.applies_to_adapter(&adapter_lowercase_info));
156
157 let mut applicable_cases = Vec::with_capacity(test.params.failures.len());
158 let mut failure_application_reasons = FailureApplicationReasons::empty();
159 let mut flaky = false;
160 for failure in &test.params.failures {
161 if let Some(reasons) = failure.applies_to_adapter(&adapter_lowercase_info) {
162 failure_application_reasons.insert(reasons);
163 applicable_cases.push(failure.clone());
164 flaky |= matches!(failure.behavior, FailureBehavior::Ignore);
165 }
166 }
167
168 let mut skip = false;
169 let running_msg = if let Some(reasons) = skip_application_reason {
170 skip = true;
171
172 let names: ArrayVec<_, 4> = reasons.iter_names().map(|(name, _)| name).collect();
173 let names_text = names.join(" | ");
174
175 format!("Skipped Failure: {names_text}")
176 } else if !unsupported_reasons.is_empty() {
177 skip = true;
178 format!("Unsupported: {}", unsupported_reasons.join(" | "))
179 } else if !failure_application_reasons.is_empty() {
180 if cfg!(target_arch = "wasm32") {
181 skip = true;
182 }
183
184 let names: ArrayVec<_, 4> = failure_application_reasons
185 .iter_names()
186 .map(|(name, _)| name)
187 .collect();
188 let names_text = names.join(" & ");
189 let flaky_text = if flaky { " Flaky " } else { " " };
190
191 format!("Executed{flaky_text}Failure: {names_text}")
192 } else {
193 String::from("Executed")
194 };
195
196 Self {
197 skip,
198 failure_application_reasons,
199 failures: applicable_cases,
200 running_msg,
201 }
202 }
203}