From 53e2c95dc80ed38b6acbc041547d169d27e99804 Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Fri, 2 Jul 2021 00:56:19 -0400 Subject: [PATCH] Fix wgpu-info display by moving masks to associated functions --- wgpu-core/src/instance.rs | 2 +- wgpu-types/src/lib.rs | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) 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) } }