diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index c74fe50e48..5849c73a44 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -210,7 +210,7 @@ impl Adapter { let caps = &self.raw.capabilities; if !caps.downlevel.is_webgpu_compliant() { - let missing_flags = wgt::DownlevelFlags::COMPLIANT - caps.downlevel.flags; + let missing_flags = wgt::DownlevelFlags::compliant() - caps.downlevel.flags; log::warn!( "Missing downlevel flags: {:?}\n{}", missing_flags, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 4175ee1421..44cb1e432d 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -480,11 +480,18 @@ bitflags::bitflags! { /// /// This is a native only feature. const SPIRV_SHADER_PASSTHROUGH = 0x0000_0800_0000_0000; + } +} - /// Features which are part of the upstream WebGPU standard. - const ALL_WEBGPU = 0x0000_0000_0000_FFFF; - /// Features that are only available when targeting native (not web). - const ALL_NATIVE = 0xFFFF_FFFF_FFFF_0000; +impl Features { + /// Mask of all features which are part of the upstream WebGPU standard. + pub const fn all_webgpu_mask() -> Self { + Self::from_bits_truncate(0x0000_0000_0000_FFFF) + } + + /// Mask of all features that are only available when targeting native (not web). + pub const fn all_native_mask() -> Self { + Self::from_bits_truncate(0xFFFF_FFFF_FFFF_0000) } } @@ -611,7 +618,7 @@ pub struct DownlevelCapabilities { impl Default for DownlevelCapabilities { fn default() -> Self { Self { - flags: DownlevelFlags::COMPLIANT, + flags: DownlevelFlags::compliant(), limits: DownlevelLimits::default(), shader_model: ShaderModel::Sm5, } @@ -624,7 +631,7 @@ impl DownlevelCapabilities { /// If this returns false, some parts of the API will result in validation errors where they would not normally. /// These parts can be determined by the values in this structure. pub fn is_webgpu_compliant(&self) -> bool { - self.flags.contains(DownlevelFlags::COMPLIANT) + self.flags.contains(DownlevelFlags::compliant()) && self.limits == DownlevelLimits::default() && self.shader_model >= ShaderModel::Sm5 } @@ -657,8 +664,16 @@ bitflags::bitflags! { const INDEPENDENT_BLENDING = 0x0000_0200; /// Supports samplers with anisotropic filtering const ANISOTROPIC_FILTERING = 0x0001_0000; - /// All flags are in their compliant state. - const COMPLIANT = 0x0000_13FF; + } +} + +impl DownlevelFlags { + /// All flags that indicate if the backend is WebGPU compliant + pub const fn compliant() -> Self { + // We use manual bit twiddling to make this a const fn as `Sub` and `.remove` aren't const + + // WebGPU doesn't actually require aniso + Self::from_bits_truncate(Self::all().bits() & !Self::ANISOTROPIC_FILTERING.bits) } } diff --git a/wgpu/examples/hello-compute/tests.rs b/wgpu/examples/hello-compute/tests.rs index 2e2ceead65..89fab4bacb 100644 --- a/wgpu/examples/hello-compute/tests.rs +++ b/wgpu/examples/hello-compute/tests.rs @@ -74,7 +74,7 @@ fn test_compute_overflow() { #[test] fn test_multithreaded_compute() { initialize_test( - TestParameters::default().backend_failures(wgpu::Backends::GL), + TestParameters::default().backend_failure(wgpu::Backends::GL), |ctx| { use std::{sync::mpsc, thread, time::Duration}; diff --git a/wgpu/examples/mipmap/main.rs b/wgpu/examples/mipmap/main.rs index eb45157286..d084344fad 100644 --- a/wgpu/examples/mipmap/main.rs +++ b/wgpu/examples/mipmap/main.rs @@ -483,7 +483,7 @@ fn mipmap() { height: 768, optional_features: wgpu::Features::default(), base_test_parameters: framework::test_common::TestParameters::default() - .backend_failures(wgpu::Backends::VULKAN | wgpu::Backends::GL), + .backend_failure(wgpu::Backends::GL), tolerance: 25, max_outliers: 3000, // Mipmap sampling is highly variant between impls. This is currently bounded by AMD on mac }); diff --git a/wgpu/tests/common/mod.rs b/wgpu/tests/common/mod.rs index 6087aefb1e..f07d748fbe 100644 --- a/wgpu/tests/common/mod.rs +++ b/wgpu/tests/common/mod.rs @@ -227,25 +227,33 @@ pub fn initialize_test(parameters: TestParameters, test_function: impl FnOnce(Te let always = backend_failure.is_none() && vendor_failure.is_none() && adapter_failure.is_none(); - let expect_failure_backend = backend_failure - .map(|f| f.contains(wgpu::Backends::from(adapter_info.backend))) - .unwrap_or(true); - let expect_failure_vendor = vendor_failure - .map(|v| v == adapter_info.vendor) - .unwrap_or(true); + let expect_failure_backend = + backend_failure.map(|f| f.contains(wgpu::Backends::from(adapter_info.backend))); + let expect_failure_vendor = vendor_failure.map(|v| v == adapter_info.vendor); let expect_failure_adapter = adapter_failure .as_deref() - .map(|f| adapter_lowercase_name.contains(f)) - .unwrap_or(true); + .map(|f| adapter_lowercase_name.contains(f)); - if expect_failure_backend && expect_failure_vendor && expect_failure_adapter { + if expect_failure_backend.unwrap_or(true) + && expect_failure_vendor.unwrap_or(true) + && expect_failure_adapter.unwrap_or(true) + { if always { Some((FailureReasons::ALWAYS, *segfault)) } else { let mut reason = FailureReasons::empty(); - reason.set(FailureReasons::BACKEND, expect_failure_backend); - reason.set(FailureReasons::VENDOR, expect_failure_vendor); - reason.set(FailureReasons::ADAPTER, expect_failure_adapter); + reason.set( + FailureReasons::BACKEND, + expect_failure_backend.unwrap_or(false), + ); + reason.set( + FailureReasons::VENDOR, + expect_failure_vendor.unwrap_or(false), + ); + reason.set( + FailureReasons::ADAPTER, + expect_failure_adapter.unwrap_or(false), + ); Some((reason, *segfault)) } } else { diff --git a/wgpu/tests/vertex_indices/mod.rs b/wgpu/tests/vertex_indices/mod.rs index bc82644ccd..e72b3a7f2b 100644 --- a/wgpu/tests/vertex_indices/mod.rs +++ b/wgpu/tests/vertex_indices/mod.rs @@ -143,7 +143,7 @@ fn draw_vertex_offset() { initialize_test( TestParameters::default() .test_features() - .backend_failures(wgpu::Backends::DX12 | wgpu::Backends::DX11), + .backend_failure(wgpu::Backends::DX12 | wgpu::Backends::DX11), |ctx| { pulling_common(ctx, &[0, 1, 2, 3, 4, 5], |cmb| { cmb.draw(0..3, 0..1); @@ -167,7 +167,7 @@ fn draw_instanced_offset() { initialize_test( TestParameters::default() .test_features() - .backend_failures(wgpu::Backends::DX12 | wgpu::Backends::DX11), + .backend_failure(wgpu::Backends::DX12 | wgpu::Backends::DX11), |ctx| { pulling_common(ctx, &[0, 1, 2, 3, 4, 5], |cmb| { cmb.draw(0..3, 0..1);