wgpu_types/
features.rs

1use crate::{link_to_wgpu_docs, link_to_wgpu_item, VertexFormat};
2#[cfg(feature = "serde")]
3use alloc::fmt;
4use alloc::vec::Vec;
5#[cfg(feature = "serde")]
6use bitflags::parser::{ParseError, ParseHex, WriteHex};
7#[cfg(feature = "serde")]
8use bitflags::Bits;
9use bitflags::Flags;
10#[cfg(feature = "serde")]
11use core::mem::size_of;
12#[cfg(feature = "serde")]
13use serde::{Deserialize, Serialize};
14
15pub use webgpu_impl::*;
16mod webgpu_impl {
17    //! Constant values for [`super::FeaturesWebGPU`], separated so they can be picked up by
18    //! `cbindgen` in `mozilla-central` (where Firefox is developed).
19    #![allow(missing_docs)]
20
21    #[doc(hidden)]
22    pub const WEBGPU_FEATURE_DEPTH_CLIP_CONTROL: u64 = 1 << 0;
23
24    #[doc(hidden)]
25    pub const WEBGPU_FEATURE_DEPTH32FLOAT_STENCIL8: u64 = 1 << 1;
26
27    #[doc(hidden)]
28    pub const WEBGPU_FEATURE_TEXTURE_COMPRESSION_BC: u64 = 1 << 2;
29
30    #[doc(hidden)]
31    pub const WEBGPU_FEATURE_TEXTURE_COMPRESSION_BC_SLICED_3D: u64 = 1 << 3;
32
33    #[doc(hidden)]
34    pub const WEBGPU_FEATURE_TEXTURE_COMPRESSION_ETC2: u64 = 1 << 4;
35
36    #[doc(hidden)]
37    pub const WEBGPU_FEATURE_TEXTURE_COMPRESSION_ASTC: u64 = 1 << 5;
38
39    #[doc(hidden)]
40    pub const WEBGPU_FEATURE_TEXTURE_COMPRESSION_ASTC_SLICED_3D: u64 = 1 << 6;
41
42    #[doc(hidden)]
43    pub const WEBGPU_FEATURE_TIMESTAMP_QUERY: u64 = 1 << 7;
44
45    #[doc(hidden)]
46    pub const WEBGPU_FEATURE_INDIRECT_FIRST_INSTANCE: u64 = 1 << 8;
47
48    #[doc(hidden)]
49    pub const WEBGPU_FEATURE_SHADER_F16: u64 = 1 << 9;
50
51    #[doc(hidden)]
52    pub const WEBGPU_FEATURE_RG11B10UFLOAT_RENDERABLE: u64 = 1 << 10;
53
54    #[doc(hidden)]
55    pub const WEBGPU_FEATURE_BGRA8UNORM_STORAGE: u64 = 1 << 11;
56
57    #[doc(hidden)]
58    pub const WEBGPU_FEATURE_FLOAT32_FILTERABLE: u64 = 1 << 12;
59
60    #[doc(hidden)]
61    pub const WEBGPU_FEATURE_FLOAT32_BLENDABLE: u64 = 1 << 13;
62
63    #[doc(hidden)]
64    pub const WEBGPU_FEATURE_DUAL_SOURCE_BLENDING: u64 = 1 << 14;
65
66    #[doc(hidden)]
67    pub const WEBGPU_FEATURE_CLIP_DISTANCES: u64 = 1 << 15;
68
69    #[doc(hidden)]
70    pub const WEBGPU_FEATURE_IMMEDIATES: u64 = 1 << 16;
71}
72
73macro_rules! bitflags_array_impl {
74    ($impl_name:ident $inner_name:ident $name:ident $op:tt $($struct_names:ident)*) => (
75        impl core::ops::$impl_name for $name {
76            type Output = Self;
77
78            #[inline]
79            fn $inner_name(self, other: Self) -> Self {
80                Self {
81                    $($struct_names: self.$struct_names $op other.$struct_names,)*
82                }
83            }
84        }
85    )
86}
87
88macro_rules! bitflags_array_impl_assign {
89    ($impl_name:ident $inner_name:ident $name:ident $op:tt $($struct_names:ident)*) => (
90        impl core::ops::$impl_name for $name {
91            #[inline]
92            fn $inner_name(&mut self, other: Self) {
93                $(self.$struct_names $op other.$struct_names;)*
94            }
95        }
96    )
97}
98
99macro_rules! bit_array_impl {
100    ($impl_name:ident $inner_name:ident $name:ident $op:tt) => (
101        impl core::ops::$impl_name for $name {
102            type Output = Self;
103
104            #[inline]
105            fn $inner_name(mut self, other: Self) -> Self {
106                for (inner, other) in self.0.iter_mut().zip(other.0.iter()) {
107                    *inner $op *other;
108                }
109                self
110            }
111        }
112    )
113}
114
115macro_rules! bitflags_independent_two_arg {
116    ($(#[$meta:meta])* $func_name:ident $($struct_names:ident)*) => (
117        $(#[$meta])*
118        pub const fn $func_name(self, other:Self) -> Self {
119            Self { $($struct_names: self.$struct_names.$func_name(other.$struct_names),)* }
120        }
121    )
122}
123
124// For the most part this macro should not be modified, most configuration should be possible
125// without changing this macro.
126/// Macro for creating sets of bitflags, we need this because there are almost more flags than bits
127/// in a u64, we can't use a u128 because of FFI, and the number of flags is increasing.
128macro_rules! bitflags_array {
129    (
130        $(#[$outer:meta])*
131        pub struct $name:ident: [$T:ty; $Len:expr];
132
133        $(
134            $(#[$bit_outer:meta])*
135            $vis:vis struct $inner_name:ident $lower_inner_name:ident {
136                $(
137                    $(#[$inner:ident $($args:tt)*])*
138                    const $Flag:tt = $value:expr;
139                )*
140            }
141        )*
142    ) => {
143        $(
144            bitflags::bitflags! {
145                $(#[$bit_outer])*
146                $vis struct $inner_name: $T {
147                    $(
148                        $(#[$inner $($args)*])*
149                        const $Flag = $value;
150                    )*
151                }
152            }
153        )*
154
155        $(#[$outer])*
156        pub struct $name {
157            $(
158                #[allow(missing_docs)]
159                $vis $lower_inner_name: $inner_name,
160            )*
161        }
162
163        /// Bits from `Features` in array form
164        #[derive(Default, Copy, Clone, Debug, PartialEq, Eq)]
165        #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
166        pub struct FeatureBits(pub [$T; $Len]);
167
168        bitflags_array_impl! { BitOr bitor $name | $($lower_inner_name)* }
169        bitflags_array_impl! { BitAnd bitand $name & $($lower_inner_name)* }
170        bitflags_array_impl! { BitXor bitxor $name ^ $($lower_inner_name)* }
171        impl core::ops::Not for $name {
172            type Output = Self;
173
174            #[inline]
175            fn not(self) -> Self {
176                Self {
177                   $($lower_inner_name: !self.$lower_inner_name,)*
178                }
179            }
180        }
181        bitflags_array_impl! { Sub sub $name - $($lower_inner_name)* }
182
183        #[cfg(feature = "serde")]
184        impl Serialize for $name {
185            fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
186            where
187                S: serde::Serializer,
188            {
189                bitflags::serde::serialize(self, serializer)
190            }
191        }
192
193        #[cfg(feature = "serde")]
194        impl<'de> Deserialize<'de> for $name {
195            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
196            where
197                D: serde::Deserializer<'de>,
198            {
199                bitflags::serde::deserialize(deserializer)
200            }
201        }
202
203        impl core::fmt::Display for $name {
204            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
205                let mut iter = self.iter_names();
206                // simple look ahead
207                let mut next = iter.next();
208                while let Some((name, _)) = next {
209                    f.write_str(name)?;
210                    next = iter.next();
211                    if next.is_some() {
212                        f.write_str(" | ")?;
213                    }
214                }
215                Ok(())
216            }
217        }
218
219        bitflags_array_impl_assign! { BitOrAssign bitor_assign $name |= $($lower_inner_name)* }
220        bitflags_array_impl_assign! { BitAndAssign bitand_assign $name &= $($lower_inner_name)* }
221        bitflags_array_impl_assign! { BitXorAssign bitxor_assign $name ^= $($lower_inner_name)* }
222
223        bit_array_impl! { BitOr bitor FeatureBits |= }
224        bit_array_impl! { BitAnd bitand FeatureBits &= }
225        bit_array_impl! { BitXor bitxor FeatureBits ^= }
226
227        impl core::ops::Not for FeatureBits {
228            type Output = Self;
229
230            #[inline]
231            fn not(self) -> Self {
232                let [$($lower_inner_name,)*] = self.0;
233                Self([$(!$lower_inner_name,)*])
234            }
235        }
236
237        #[cfg(feature = "serde")]
238        impl WriteHex for FeatureBits {
239            fn write_hex<W: fmt::Write>(&self, mut writer: W) -> fmt::Result {
240                let [$($lower_inner_name,)*] = self.0;
241                let mut wrote = false;
242                let mut stager = alloc::string::String::with_capacity(size_of::<$T>() * 2);
243                // we don't want to write it if it's just zero as there may be multiple zeros
244                // resulting in something like "00" being written out. We do want to write it if
245                // there has already been something written though.
246                $(if ($lower_inner_name != 0) || wrote {
247                    // First we write to a staging string, then we add any zeros (e.g if #1
248                    // is f and a u8 and #2 is a then the two combined would be f0a which requires
249                    // a 0 inserted)
250                    $lower_inner_name.write_hex(&mut stager)?;
251                    if (stager.len() != size_of::<$T>() * 2) && wrote {
252                        let zeros_to_write = (size_of::<$T>() * 2) - stager.len();
253                        for _ in 0..zeros_to_write {
254                            writer.write_char('0')?
255                        }
256                    }
257                    writer.write_str(&stager)?;
258                    stager.clear();
259                    wrote = true;
260                })*
261                if !wrote {
262                    writer.write_str("0")?;
263                }
264                Ok(())
265            }
266        }
267
268        #[cfg(feature = "serde")]
269        impl ParseHex for FeatureBits {
270            fn parse_hex(input: &str) -> Result<Self, ParseError> {
271
272                let mut unset = Self::EMPTY;
273                let mut end = input.len();
274                if end == 0 {
275                    return Err(ParseError::empty_flag())
276                }
277                // we iterate starting at the least significant places and going up
278                for (idx, _) in [$(stringify!($lower_inner_name),)*].iter().enumerate().rev() {
279                    // A byte is two hex places - u8 (1 byte) = 0x00 (2 hex places).
280                    let checked_start = end.checked_sub(size_of::<$T>() * 2);
281                    let start = checked_start.unwrap_or(0);
282
283                    let cur_input = &input[start..end];
284                    unset.0[idx] = <$T>::from_str_radix(cur_input, 16)
285                        .map_err(|_|ParseError::invalid_hex_flag(cur_input))?;
286
287                    end = start;
288
289                    if let None = checked_start {
290                        break;
291                    }
292                }
293                Ok(unset)
294            }
295        }
296
297        impl bitflags::Bits for FeatureBits {
298            const EMPTY: Self = $name::empty().bits();
299
300            const ALL: Self = $name::all().bits();
301        }
302
303        impl Flags for $name {
304            const FLAGS: &'static [bitflags::Flag<Self>] = $name::FLAGS;
305
306            type Bits = FeatureBits;
307
308            fn bits(&self) -> FeatureBits {
309                FeatureBits([
310                    $(self.$lower_inner_name.bits(),)*
311                ])
312            }
313
314            fn from_bits_retain(bits: FeatureBits) -> Self {
315                let [$($lower_inner_name,)*] = bits.0;
316                Self {
317                    $($lower_inner_name: $inner_name::from_bits_retain($lower_inner_name),)*
318                }
319            }
320
321            fn empty() -> Self {
322                Self::empty()
323            }
324
325            fn all() -> Self {
326                Self::all()
327            }
328        }
329
330        impl $name {
331            pub(crate) const FLAGS: &'static [bitflags::Flag<Self>] = &[
332                $(
333                    $(
334                        bitflags::Flag::new(stringify!($Flag), $name::$Flag),
335                    )*
336                )*
337            ];
338
339            /// Gets the set flags as a container holding an array of bits.
340            pub const fn bits(&self) -> FeatureBits {
341                FeatureBits([
342                    $(self.$lower_inner_name.bits(),)*
343                ])
344            }
345
346            /// Returns self with no flags set.
347            pub const fn empty() -> Self {
348                Self {
349                    $($lower_inner_name: $inner_name::empty(),)*
350                }
351            }
352
353            /// Returns self with all flags set.
354            pub const fn all() -> Self {
355                Self {
356                    $($lower_inner_name: $inner_name::all(),)*
357                }
358            }
359
360            /// Whether all the bits set in `other` are all set in `self`
361            pub const fn contains(self, other:Self) -> bool {
362                // we need an annoying true to catch the last && >:(
363                $(self.$lower_inner_name.contains(other.$lower_inner_name) &&)* true
364            }
365
366            /// Returns whether any bit set in `self` matched any bit set in `other`.
367            pub const fn intersects(self, other:Self) -> bool {
368                $(self.$lower_inner_name.intersects(other.$lower_inner_name) ||)* false
369            }
370
371            /// Returns whether there is no flag set.
372            pub const fn is_empty(self) -> bool {
373                $(self.$lower_inner_name.is_empty() &&)* true
374            }
375
376            /// Returns whether the struct has all flags set.
377            pub const fn is_all(self) -> bool {
378                $(self.$lower_inner_name.is_all() &&)* true
379            }
380
381            bitflags_independent_two_arg! {
382                /// Bitwise or - `self | other`
383                union $($lower_inner_name)*
384            }
385
386            bitflags_independent_two_arg! {
387                /// Bitwise and - `self & other`
388                intersection $($lower_inner_name)*
389            }
390
391            bitflags_independent_two_arg! {
392                /// Bitwise and of the complement of other - `self & !other`
393                difference $($lower_inner_name)*
394            }
395
396            bitflags_independent_two_arg! {
397                /// Bitwise xor - `self ^ other`
398                symmetric_difference $($lower_inner_name)*
399            }
400
401            /// Bitwise not - `!self`
402            pub const fn complement(self) -> Self {
403                Self {
404                    $($lower_inner_name: self.$lower_inner_name.complement(),)*
405                }
406            }
407
408            /// Calls [`Self::insert`] if `set` is true and otherwise calls [`Self::remove`].
409            pub fn set(&mut self, other:Self, set: bool) {
410                $(self.$lower_inner_name.set(other.$lower_inner_name, set);)*
411            }
412
413            /// Inserts specified flag(s) into self
414            pub fn insert(&mut self, other:Self) {
415                $(self.$lower_inner_name.insert(other.$lower_inner_name);)*
416            }
417
418            /// Removes specified flag(s) from self
419            pub fn remove(&mut self, other:Self) {
420                $(self.$lower_inner_name.remove(other.$lower_inner_name);)*
421            }
422
423            /// Toggles specified flag(s) in self
424            pub fn toggle(&mut self, other:Self) {
425                $(self.$lower_inner_name.toggle(other.$lower_inner_name);)*
426            }
427
428            /// Takes in [`FeatureBits`] and returns None if there are invalid bits or otherwise Self with
429            /// those bits set
430            pub const fn from_bits(bits:FeatureBits) -> Option<Self> {
431                let [$($lower_inner_name,)*] = bits.0;
432                // The ? operator does not work in a const context.
433                Some(Self {
434                    $(
435                        $lower_inner_name: match $inner_name::from_bits($lower_inner_name) {
436                            Some(some) => some,
437                            None => return None,
438                        },
439                    )*
440                })
441            }
442
443            /// Takes in [`FeatureBits`] and returns Self with only valid bits (all other bits removed)
444            pub const fn from_bits_truncate(bits:FeatureBits) -> Self {
445                let [$($lower_inner_name,)*] = bits.0;
446                Self { $($lower_inner_name: $inner_name::from_bits_truncate($lower_inner_name),)* }
447            }
448
449            /// Takes in [`FeatureBits`] and returns Self with all bits that were set without removing
450            /// invalid bits
451            pub const fn from_bits_retain(bits:FeatureBits) -> Self {
452                let [$($lower_inner_name,)*] = bits.0;
453                Self { $($lower_inner_name: $inner_name::from_bits_retain($lower_inner_name),)* }
454            }
455
456            /// Takes in a name and returns Self if it matches or none if the name does not match
457            /// the name of any of the flags. Name is capitalisation dependent.
458            pub fn from_name(name: &str) -> Option<Self> {
459                match name {
460                    $(
461                        $(
462                            stringify!($Flag) => Some(Self::$Flag),
463                        )*
464                    )*
465                    _ => None,
466                }
467            }
468
469            /// Combines the features from the internal flags into the entire features struct
470            pub fn from_internal_flags($($lower_inner_name: $inner_name,)*) -> Self {
471                Self {
472                    $($lower_inner_name,)*
473                }
474            }
475
476            /// Returns an iterator over the set flags.
477            pub const fn iter(&self) -> bitflags::iter::Iter<$name> {
478                bitflags::iter::Iter::__private_const_new($name::FLAGS, *self, *self)
479            }
480
481            /// Returns an iterator over the set flags and their names.
482            pub const fn iter_names(&self) -> bitflags::iter::IterNames<$name> {
483                bitflags::iter::IterNames::__private_const_new($name::FLAGS, *self, *self)
484            }
485
486            $(
487                $(
488                    $(#[$inner $($args)*])*
489                    // We need this for structs with only a member.
490                    #[allow(clippy::needless_update)]
491                    pub const $Flag: Self = Self {
492                        $lower_inner_name: $inner_name::from_bits_truncate($value),
493                        ..Self::empty()
494                    };
495                )*
496            )*
497        }
498
499        $(
500            impl From<$inner_name> for Features {
501                // We need this for structs with only a member.
502                #[allow(clippy::needless_update)]
503                fn from($lower_inner_name: $inner_name) -> Self {
504                    Self {
505                        $lower_inner_name,
506                        ..Self::empty()
507                    }
508                }
509            }
510        )*
511    };
512}
513
514impl From<FeatureBits> for Features {
515    fn from(value: FeatureBits) -> Self {
516        Self::from_bits_retain(value)
517    }
518}
519
520impl From<Features> for FeatureBits {
521    fn from(value: Features) -> Self {
522        value.bits()
523    }
524}
525
526bitflags_array! {
527    /// Features that are not guaranteed to be supported.
528    ///
529    /// These are either part of the webgpu standard, or are extension features supported by
530    /// wgpu when targeting native.
531    ///
532    /// If you want to use a feature, you need to first verify that the adapter supports
533    /// the feature. If the adapter does not support the feature, requesting a device with it enabled
534    /// will panic.
535    ///
536    /// Corresponds to [WebGPU `GPUFeatureName`](
537    /// https://gpuweb.github.io/gpuweb/#enumdef-gpufeaturename).
538    #[repr(C)]
539    #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
540    pub struct Features: [u64; 2];
541
542    /// Features that are not guaranteed to be supported.
543    ///
544    /// Most of these are native-only extension features supported by wgpu only when targeting
545    /// native. A few are intended to align with a proposed WebGPU extension, and one
546    /// (`EXTERNAL_TEXTURE`) controls WebGPU-specified behavior that is not optional in the
547    /// standard, but that we don't want to make a [`crate::DownlevelFlags`] until the
548    /// implementation is more complete. For all features see [`Features`].
549    ///
550    /// If you want to use a feature, you need to first verify that the adapter supports
551    /// the feature. If the adapter does not support the feature, requesting a device with it enabled
552    /// will panic.
553    ///
554    /// Corresponds to [WebGPU `GPUFeatureName`](
555    /// https://gpuweb.github.io/gpuweb/#enumdef-gpufeaturename).
556    #[repr(transparent)]
557    #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
558    #[cfg_attr(feature = "serde", serde(transparent))]
559    #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
560    pub struct FeaturesWGPU features_wgpu {
561        /// Allows shaders to use f32 atomic load, store, add, sub, and exchange.
562        ///
563        /// Supported platforms:
564        /// - Metal (with MSL 3.0+ and Apple7+/Mac2)
565        /// - Vulkan (with [VK_EXT_shader_atomic_float])
566        ///
567        /// This is a native only feature.
568        ///
569        /// [VK_EXT_shader_atomic_float]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_shader_atomic_float.html
570        const SHADER_FLOAT32_ATOMIC = 1 << 0;
571
572        // The features starting with a ? are features that might become part of the spec or
573        // at the very least we can implement as native features; since they should cover all
574        // possible formats and capabilities across backends.
575        //
576        // ? const FORMATS_TIER_1 = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3837)
577        // ? const RW_STORAGE_TEXTURE_TIER_1 = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3838)
578        // ? const NORM16_FILTERABLE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3839)
579        // ? const NORM16_RESOLVE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3839)
580        // ? const 32BIT_FORMAT_MULTISAMPLE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3844)
581        // ? const 32BIT_FORMAT_RESOLVE = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3844)
582        // ? const TEXTURE_COMPRESSION_ASTC_HDR = 1 << ??; (https://github.com/gpuweb/gpuweb/issues/3856)
583        // TEXTURE_FORMAT_16BIT_NORM & TEXTURE_COMPRESSION_ASTC_HDR will most likely become web features as well
584        // TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES might not be necessary if we have all the texture features implemented
585
586        // Texture Formats:
587
588        /// Enables normalized `16-bit` texture formats.
589        ///
590        /// Supported platforms:
591        /// - Vulkan
592        /// - DX12
593        /// - Metal
594        ///
595        /// This is a native only feature.
596        const TEXTURE_FORMAT_16BIT_NORM = 1 << 1;
597        /// Enables ASTC HDR family of compressed textures.
598        ///
599        /// Compressed textures sacrifice some quality in exchange for significantly reduced
600        /// bandwidth usage.
601        ///
602        /// Support for this feature guarantees availability of [`TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING`] for ASTC formats with the HDR channel type.
603        /// [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] may enable additional usages.
604        ///
605        /// Supported Platforms:
606        /// - Metal
607        /// - Vulkan
608        /// - OpenGL
609        ///
610        /// This is a native only feature.
611        const TEXTURE_COMPRESSION_ASTC_HDR = 1 << 2;
612        /// Enables device specific texture format features.
613        ///
614        /// See `TextureFormatFeatures` for a listing of the features in question.
615        ///
616        /// By default only texture format properties as defined by the WebGPU specification are allowed.
617        /// Enabling this feature flag extends the features of each format to the ones supported by the current device.
618        /// Note that without this flag, read/write storage access is not allowed at all.
619        ///
620        /// This extension does not enable additional formats.
621        ///
622        /// This is a native only feature.
623        const TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES = 1 << 3;
624
625        // API:
626
627        /// Enables use of Pipeline Statistics Queries. These queries tell the count of various operations
628        /// performed between the start and stop call. Call [`RenderPass::begin_pipeline_statistics_query`] to start
629        /// a query, then call [`RenderPass::end_pipeline_statistics_query`] to stop one.
630        ///
631        /// They must be resolved using [`CommandEncoder::resolve_query_set`] into a buffer.
632        /// The rules on how these resolve into buffers are detailed in the documentation for [`PipelineStatisticsTypes`].
633        ///
634        /// Supported Platforms:
635        /// - Vulkan
636        /// - DX12
637        ///
638        /// This is a native only feature with a [proposal](https://github.com/gpuweb/gpuweb/blob/0008bd30da2366af88180b511a5d0d0c1dffbc36/proposals/pipeline-statistics-query.md) for the web.
639        ///
640        #[doc = link_to_wgpu_docs!(["`RenderPass::begin_pipeline_statistics_query`"]: "struct.RenderPass.html#method.begin_pipeline_statistics_query")]
641        #[doc = link_to_wgpu_docs!(["`RenderPass::end_pipeline_statistics_query`"]: "struct.RenderPass.html#method.end_pipeline_statistics_query")]
642        #[doc = link_to_wgpu_docs!(["`CommandEncoder::resolve_query_set`"]: "struct.CommandEncoder.html#method.resolve_query_set")]
643        /// [`PipelineStatisticsTypes`]: super::PipelineStatisticsTypes
644        const PIPELINE_STATISTICS_QUERY = 1 << 4;
645        /// Allows for timestamp queries directly on command encoders.
646        ///
647        /// Implies [`Features::TIMESTAMP_QUERY`] is supported.
648        ///
649        /// Additionally allows for timestamp writes on command encoders
650        /// using  [`CommandEncoder::write_timestamp`].
651        ///
652        /// Supported platforms:
653        /// - Vulkan
654        /// - DX12
655        /// - Metal
656        ///
657        /// This is a native only feature.
658        ///
659        #[doc = link_to_wgpu_docs!(["`CommandEncoder::write_timestamp`"]: "struct.CommandEncoder.html#method.write_timestamp")]
660        const TIMESTAMP_QUERY_INSIDE_ENCODERS = 1 << 5;
661        /// Allows for timestamp queries directly on command encoders.
662        ///
663        /// Implies [`Features::TIMESTAMP_QUERY`] & [`Features::TIMESTAMP_QUERY_INSIDE_ENCODERS`] is supported.
664        ///
665        /// Additionally allows for timestamp queries to be used inside render & compute passes using:
666        /// - [`RenderPass::write_timestamp`]
667        /// - [`ComputePass::write_timestamp`]
668        ///
669        /// Supported platforms:
670        /// - Vulkan
671        /// - DX12
672        /// - Metal (AMD & Intel, not Apple GPUs)
673        ///
674        /// This is generally not available on tile-based rasterization GPUs.
675        ///
676        /// This is a native only feature with a [proposal](https://github.com/gpuweb/gpuweb/blob/0008bd30da2366af88180b511a5d0d0c1dffbc36/proposals/timestamp-query-inside-passes.md) for the web.
677        ///
678        #[doc = link_to_wgpu_docs!(["`RenderPass::write_timestamp`"]: "struct.RenderPass.html#method.write_timestamp")]
679        #[doc = link_to_wgpu_docs!(["`ComputePass::write_timestamp`"]: "struct.ComputePass.html#method.write_timestamp")]
680        const TIMESTAMP_QUERY_INSIDE_PASSES = 1 << 6;
681        /// Webgpu only allows the MAP_READ and MAP_WRITE buffer usage to be matched with
682        /// COPY_DST and COPY_SRC respectively. This removes this requirement.
683        ///
684        /// This is only beneficial on systems that share memory between CPU and GPU. If enabled
685        /// on a system that doesn't, this can severely hinder performance. Only use if you understand
686        /// the consequences.
687        ///
688        /// Supported platforms:
689        /// - Vulkan
690        /// - DX12
691        /// - Metal
692        ///
693        /// This is a native only feature.
694        const MAPPABLE_PRIMARY_BUFFERS = 1 << 7;
695        /// Allows the user to create uniform arrays of textures in shaders:
696        ///
697        /// ex.
698        /// - `var textures: binding_array<texture_2d<f32>, 10>` (WGSL)
699        /// - `uniform texture2D textures[10]` (GLSL)
700        ///
701        /// If [`Features::STORAGE_RESOURCE_BINDING_ARRAY`] is supported as well as this, the user
702        /// may also create uniform arrays of storage textures.
703        ///
704        /// ex.
705        /// - `var textures: array<texture_storage_2d<r32float, write>, 10>` (WGSL)
706        /// - `uniform image2D textures[10]` (GLSL)
707        ///
708        /// This capability allows them to exist and to be indexed by dynamically uniform
709        /// values.
710        ///
711        /// Supported platforms:
712        /// - DX12
713        /// - Metal (with MSL 2.0+ on macOS 10.13+)
714        /// - Vulkan
715        ///
716        /// This is a native only feature.
717        const TEXTURE_BINDING_ARRAY = 1 << 8;
718        /// Allows the user to create arrays of buffers in shaders:
719        ///
720        /// ex.
721        /// - `var<uniform> buffer_array: array<MyBuffer, 10>` (WGSL)
722        /// - `uniform myBuffer { ... } buffer_array[10]` (GLSL)
723        ///
724        /// This capability allows them to exist and to be indexed by dynamically uniform
725        /// values.
726        ///
727        /// If [`Features::STORAGE_RESOURCE_BINDING_ARRAY`] is supported as well as this, the user
728        /// may also create arrays of storage buffers.
729        ///
730        /// ex.
731        /// - `var<storage> buffer_array: array<MyBuffer, 10>` (WGSL)
732        /// - `buffer myBuffer { ... } buffer_array[10]` (GLSL)
733        ///
734        /// Supported platforms:
735        /// - Vulkan
736        ///
737        /// This is a native only feature.
738        const BUFFER_BINDING_ARRAY = 1 << 9;
739        /// Allows the user to create uniform arrays of storage buffers or textures in shaders,
740        /// if resp. [`Features::BUFFER_BINDING_ARRAY`] or [`Features::TEXTURE_BINDING_ARRAY`]
741        /// is supported.
742        ///
743        /// This capability allows them to exist and to be indexed by dynamically uniform
744        /// values.
745        ///
746        /// Supported platforms:
747        /// - Metal (with MSL 2.2+ on macOS 10.13+)
748        /// - Vulkan
749        ///
750        /// This is a native only feature.
751        const STORAGE_RESOURCE_BINDING_ARRAY = 1 << 10;
752        /// Allows shaders to index sampled texture and storage buffer resource arrays with dynamically non-uniform values:
753        ///
754        /// ex. `texture_array[vertex_data]`
755        ///
756        /// In order to use this capability, the corresponding GLSL extension must be enabled like so:
757        ///
758        /// `#extension GL_EXT_nonuniform_qualifier : require`
759        ///
760        /// and then used either as `nonuniformEXT` qualifier in variable declaration:
761        ///
762        /// ex. `layout(location = 0) nonuniformEXT flat in int vertex_data;`
763        ///
764        /// or as `nonuniformEXT` constructor:
765        ///
766        /// ex. `texture_array[nonuniformEXT(vertex_data)]`
767        ///
768        /// WGSL and HLSL do not need any extension.
769        ///
770        /// Supported platforms:
771        /// - DX12
772        /// - Metal (with MSL 2.0+ on macOS 10.13+)
773        /// - Vulkan 1.2+ (or VK_EXT_descriptor_indexing)'s shaderSampledImageArrayNonUniformIndexing & shaderStorageBufferArrayNonUniformIndexing feature)
774        ///
775        /// This is a native only feature.
776        const SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING = 1 << 11;
777        /// Allows shaders to index storage texture resource arrays with dynamically non-uniform values:
778        ///
779        /// ex. `texture_array[vertex_data]`
780        ///
781        /// Supported platforms:
782        /// - DX12
783        /// - Metal (with MSL 2.0+ on macOS 10.13+)
784        /// - Vulkan 1.2+ (or VK_EXT_descriptor_indexing)'s shaderStorageTextureArrayNonUniformIndexing feature)
785        ///
786        /// This is a native only feature.
787        const STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING = 1 << 12;
788        /// Allows the user to create bind groups containing arrays with less bindings than the BindGroupLayout.
789        ///
790        /// Supported platforms:
791        /// - Vulkan
792        /// - DX12
793        ///
794        /// This is a native only feature.
795        const PARTIALLY_BOUND_BINDING_ARRAY = 1 << 13;
796        /// Allows the user to call [`RenderPass::multi_draw_indirect_count`] and [`RenderPass::multi_draw_indexed_indirect_count`].
797        ///
798        /// This allows the use of a buffer containing the actual number of draw calls. This feature being present also implies
799        /// that all calls to [`RenderPass::multi_draw_indirect`] and [`RenderPass::multi_draw_indexed_indirect`] are not being emulated
800        /// with a series of `draw_indirect` calls.
801        ///
802        /// Supported platforms:
803        /// - DX12
804        /// - Vulkan 1.2+ (or VK_KHR_draw_indirect_count)
805        ///
806        /// This is a native only feature.
807        ///
808        #[doc = link_to_wgpu_docs!(["`RenderPass::multi_draw_indirect`"]: "struct.RenderPass.html#method.multi_draw_indirect")]
809        #[doc = link_to_wgpu_docs!(["`RenderPass::multi_draw_indexed_indirect`"]: "struct.RenderPass.html#method.multi_draw_indexed_indirect")]
810        #[doc = link_to_wgpu_docs!(["`RenderPass::multi_draw_indirect_count`"]: "struct.RenderPass.html#method.multi_draw_indirect_count")]
811        #[doc = link_to_wgpu_docs!(["`RenderPass::multi_draw_indexed_indirect_count`"]: "struct.RenderPass.html#method.multi_draw_indexed_indirect_count")]
812        const MULTI_DRAW_INDIRECT_COUNT = 1 << 15;
813        /// Allows the use of [`AddressMode::ClampToBorder`] with a border color
814        /// of [`SamplerBorderColor::Zero`].
815        ///
816        /// Supported platforms:
817        /// - DX12
818        /// - Vulkan
819        /// - Metal
820        /// - OpenGL
821        ///
822        /// This is a native only feature.
823        ///
824        /// [`AddressMode::ClampToBorder`]: super::AddressMode::ClampToBorder
825        /// [`SamplerBorderColor::Zero`]: super::SamplerBorderColor::Zero
826        const ADDRESS_MODE_CLAMP_TO_ZERO = 1 << 17;
827        /// Allows the use of [`AddressMode::ClampToBorder`] with a border color
828        /// other than [`SamplerBorderColor::Zero`].
829        ///
830        /// Supported platforms:
831        /// - DX12
832        /// - Vulkan
833        /// - Metal (macOS 10.12+ only)
834        /// - OpenGL
835        ///
836        /// This is a native only feature.
837        ///
838        /// [`AddressMode::ClampToBorder`]: super::AddressMode::ClampToBorder
839        /// [`SamplerBorderColor::Zero`]: super::SamplerBorderColor::Zero
840        const ADDRESS_MODE_CLAMP_TO_BORDER = 1 << 18;
841        /// Allows the user to set [`PolygonMode::Line`] in [`PrimitiveState::polygon_mode`]
842        ///
843        /// This allows drawing polygons/triangles as lines (wireframe) instead of filled
844        ///
845        /// Supported platforms:
846        /// - DX12
847        /// - Vulkan
848        /// - Metal
849        ///
850        /// This is a native only feature.
851        ///
852        /// [`PrimitiveState::polygon_mode`]: super::PrimitiveState
853        /// [`PolygonMode::Line`]: super::PolygonMode::Line
854        const POLYGON_MODE_LINE = 1 << 19;
855        /// Allows the user to set [`PolygonMode::Point`] in [`PrimitiveState::polygon_mode`]
856        ///
857        /// This allows only drawing the vertices of polygons/triangles instead of filled
858        ///
859        /// Supported platforms:
860        /// - Vulkan
861        ///
862        /// This is a native only feature.
863        ///
864        /// [`PrimitiveState::polygon_mode`]: super::PrimitiveState
865        /// [`PolygonMode::Point`]: super::PolygonMode::Point
866        const POLYGON_MODE_POINT = 1 << 20;
867        /// Allows the user to set a overestimation-conservative-rasterization in [`PrimitiveState::conservative`]
868        ///
869        /// Processing of degenerate triangles/lines is hardware specific.
870        /// Only triangles are supported.
871        ///
872        /// Supported platforms:
873        /// - Vulkan
874        ///
875        /// This is a native only feature.
876        ///
877        /// [`PrimitiveState::conservative`]: super::PrimitiveState::conservative
878        const CONSERVATIVE_RASTERIZATION = 1 << 21;
879        /// Enables bindings of writable storage buffers and textures visible to vertex shaders.
880        ///
881        /// Note: some (tiled-based) platforms do not support vertex shaders with any side-effects.
882        ///
883        /// Supported Platforms:
884        /// - All
885        ///
886        /// This is a native only feature.
887        const VERTEX_WRITABLE_STORAGE = 1 << 22;
888        /// Enables clear to zero for textures.
889        ///
890        /// Supported platforms:
891        /// - All
892        ///
893        /// This is a native only feature.
894        const CLEAR_TEXTURE = 1 << 23;
895        /// Enables multiview render passes and `builtin(view_index)` in vertex/mesh shaders.
896        ///
897        /// Supported platforms:
898        /// - Vulkan
899        /// - Metal
900        /// - DX12
901        /// - OpenGL (web only)
902        ///
903        /// This is a native only feature.
904        const MULTIVIEW = 1 << 26;
905        /// Enables using 64-bit types for vertex attributes.
906        ///
907        /// Requires SHADER_FLOAT64.
908        ///
909        /// Supported Platforms: N/A
910        ///
911        /// This is a native only feature.
912        const VERTEX_ATTRIBUTE_64BIT = 1 << 27;
913        /// Enables image atomic fetch add, and, xor, or, min, and max for R32Uint and R32Sint textures.
914        ///
915        /// Supported platforms:
916        /// - Vulkan
917        /// - DX12
918        /// - Metal (with MSL 3.1+)
919        ///
920        /// This is a native only feature.
921        const TEXTURE_ATOMIC = 1 << 28;
922        /// Allows for creation of textures of format [`TextureFormat::NV12`]
923        ///
924        /// Supported platforms:
925        /// - DX12
926        /// - Vulkan
927        ///
928        /// This is a native only feature.
929        ///
930        /// [`TextureFormat::NV12`]: super::TextureFormat::NV12
931        const TEXTURE_FORMAT_NV12 = 1 << 29;
932        /// Allows for creation of textures of format [`TextureFormat::P010`]
933        ///
934        /// Supported platforms:
935        /// - DX12
936        /// - Vulkan
937        ///
938        /// This is a native only feature.
939        ///
940        /// [`TextureFormat::P010`]: super::TextureFormat::P010
941        const TEXTURE_FORMAT_P010 = 1 << 30;
942
943        /// Allows for the creation and usage of `ExternalTexture`s, and bind
944        /// group layouts containing external texture `BindingType`s.
945        ///
946        /// Conceptually this should really be a [`crate::DownlevelFlags`] as
947        /// it corresponds to WebGPU's [`GPUExternalTexture`](
948        /// https://www.w3.org/TR/webgpu/#gpuexternaltexture).
949        /// However, the implementation is currently in-progress, and until it
950        /// is complete we do not want applications to ignore adapters due to
951        /// a missing downlevel flag, when they may not require this feature at
952        /// all.
953        ///
954        /// Supported platforms:
955        /// - DX12
956        /// - Metal
957        const EXTERNAL_TEXTURE = 1 << 31;
958
959        // Shader:
960
961        /// ***THIS IS EXPERIMENTAL:*** Features enabled by this may have
962        /// major bugs in it and are expected to be subject to breaking changes, suggestions
963        /// for the API exposed by this should be posted on [the ray-tracing issue](https://github.com/gfx-rs/wgpu/issues/1040)
964        ///
965        /// Allows for the creation of ray-tracing queries within shaders.
966        ///
967        /// Supported platforms:
968        /// - Vulkan
969        ///
970        /// This is a native-only feature.
971        const EXPERIMENTAL_RAY_QUERY = 1 << 32;
972        /// Enables 64-bit floating point types in SPIR-V shaders.
973        ///
974        /// Note: even when supported by GPU hardware, 64-bit floating point operations are
975        /// frequently between 16 and 64 _times_ slower than equivalent operations on 32-bit floats.
976        ///
977        /// Supported Platforms:
978        /// - Vulkan
979        ///
980        /// This is a native only feature.
981        const SHADER_F64 = 1 << 33;
982        /// Allows shaders to use i16. Not currently supported in `naga`, only available through `spirv-passthrough`.
983        ///
984        /// Supported platforms:
985        /// - Vulkan
986        ///
987        /// This is a native only feature.
988        const SHADER_I16 = 1 << 34;
989        /// Enables `builtin(primitive_index)` in fragment shaders.
990        ///
991        /// Note: enables geometry processing for pipelines using the builtin.
992        /// This may come with a significant performance impact on some hardware.
993        /// Other pipelines are not affected.
994        ///
995        /// Supported platforms:
996        /// - Vulkan
997        /// - DX12
998        /// - Metal (some)
999        /// - OpenGL (some)
1000        ///
1001        /// This is a native only feature.
1002        const SHADER_PRIMITIVE_INDEX = 1 << 35;
1003        /// Allows shaders to use the `early_depth_test` attribute.
1004        ///
1005        /// The attribute is applied to the fragment shader entry point. It can be used in two
1006        /// ways:
1007        ///
1008        ///   1. Force early depth/stencil tests:
1009        ///
1010        ///      - `@early_depth_test(force)` (WGSL)
1011        ///
1012        ///      - `layout(early_fragment_tests) in;` (GLSL)
1013        ///
1014        ///   2. Provide a conservative depth specifier that allows an additional early
1015        ///      depth test under certain conditions:
1016        ///
1017        ///      - `@early_depth_test(greater_equal/less_equal/unchanged)` (WGSL)
1018        ///
1019        ///      - `layout(depth_<greater/less/unchanged>) out float gl_FragDepth;` (GLSL)
1020        ///
1021        /// See [`EarlyDepthTest`] for more details.
1022        ///
1023        /// Supported platforms:
1024        /// - Vulkan
1025        /// - GLES 3.1+
1026        ///
1027        /// This is a native only feature.
1028        ///
1029        /// [`EarlyDepthTest`]: https://docs.rs/naga/latest/naga/ir/enum.EarlyDepthTest.html
1030        const SHADER_EARLY_DEPTH_TEST = 1 << 36;
1031        /// Allows shaders to use i64 and u64.
1032        ///
1033        /// Supported platforms:
1034        /// - Vulkan
1035        /// - DX12 (DXC only)
1036        /// - Metal (with MSL 2.3+)
1037        ///
1038        /// This is a native only feature.
1039        const SHADER_INT64 = 1 << 37;
1040        /// Allows compute and fragment shaders to use the subgroup operation
1041        /// built-ins and perform subgroup operations (except barriers).
1042        ///
1043        /// Supported Platforms:
1044        /// - Vulkan
1045        /// - DX12
1046        /// - Metal
1047        ///
1048        /// This is a native only feature.
1049        const SUBGROUP = 1 << 38;
1050        /// Allows vertex shaders to use the subgroup operation built-ins and
1051        /// perform subgroup operations (except barriers).
1052        ///
1053        /// Supported Platforms:
1054        /// - Vulkan
1055        ///
1056        /// This is a native only feature.
1057        const SUBGROUP_VERTEX = 1 << 39;
1058        /// Allows compute shaders to use the subgroup barrier.
1059        ///
1060        /// Requires [`Features::SUBGROUP`]. Without it, enables nothing.
1061        ///
1062        /// Supported Platforms:
1063        /// - Vulkan
1064        /// - Metal
1065        ///
1066        /// This is a native only feature.
1067        const SUBGROUP_BARRIER = 1 << 40;
1068        /// Allows the use of pipeline cache objects
1069        ///
1070        /// Supported platforms:
1071        /// - Vulkan
1072        ///
1073        /// Unimplemented Platforms:
1074        /// - DX12
1075        /// - Metal
1076        const PIPELINE_CACHE = 1 << 41;
1077        /// Allows shaders to use i64 and u64 atomic min and max.
1078        ///
1079        /// Supported platforms:
1080        /// - Vulkan (with VK_KHR_shader_atomic_int64)
1081        /// - DX12 (with SM 6.6+)
1082        /// - Metal (with MSL 2.4+)
1083        ///
1084        /// This is a native only feature.
1085        const SHADER_INT64_ATOMIC_MIN_MAX = 1 << 42;
1086        /// Allows shaders to use all i64 and u64 atomic operations.
1087        ///
1088        /// Supported platforms:
1089        /// - Vulkan (with VK_KHR_shader_atomic_int64)
1090        /// - DX12 (with SM 6.6+)
1091        ///
1092        /// This is a native only feature.
1093        const SHADER_INT64_ATOMIC_ALL_OPS = 1 << 43;
1094        /// Allows using the [VK_GOOGLE_display_timing] Vulkan extension.
1095        ///
1096        /// This is used for frame pacing to reduce latency, and is generally only available on Android.
1097        ///
1098        /// This feature does not have a `wgpu`-level API, and so users of wgpu wishing
1099        /// to use this functionality must access it using various `as_hal` functions,
1100        /// primarily [`Surface::as_hal()`], to then use.
1101        ///
1102        /// Supported platforms:
1103        /// - Vulkan (with [VK_GOOGLE_display_timing])
1104        ///
1105        /// This is a native only feature.
1106        ///
1107        /// [VK_GOOGLE_display_timing]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_GOOGLE_display_timing.html
1108        #[doc = link_to_wgpu_docs!(["`Surface::as_hal()`"]: "struct.Surface.html#method.as_hal")]
1109        const VULKAN_GOOGLE_DISPLAY_TIMING = 1 << 44;
1110
1111        /// Allows using the [VK_KHR_external_memory_win32] Vulkan extension.
1112        ///
1113        /// Supported platforms:
1114        /// - Vulkan (with [VK_KHR_external_memory_win32])
1115        ///
1116        /// This is a native only feature.
1117        ///
1118        /// [VK_KHR_external_memory_win32]: https://registry.khronos.org/vulkan/specs/latest/man/html/VK_KHR_external_memory_win32.html
1119        const VULKAN_EXTERNAL_MEMORY_WIN32 = 1 << 45;
1120
1121        /// Enables R64Uint image atomic min and max.
1122        ///
1123        /// Supported platforms:
1124        /// - Vulkan (with VK_EXT_shader_image_atomic_int64)
1125        /// - DX12 (with SM 6.6+)
1126        /// - Metal (with MSL 3.1+)
1127        ///
1128        /// This is a native only feature.
1129        const TEXTURE_INT64_ATOMIC = 1 << 46;
1130
1131        /// Allows uniform buffers to be bound as binding arrays.
1132        ///
1133        /// This allows:
1134        /// - Shaders to contain `var<uniform> buffer: binding_array<UniformBuffer>;`
1135        /// - The `count` field of `BindGroupLayoutEntry`s with `Uniform` buffers, to be set to `Some`.
1136        ///
1137        /// Supported platforms:
1138        /// - None (<https://github.com/gfx-rs/wgpu/issues/7149>)
1139        ///
1140        /// Potential Platforms:
1141        /// - DX12
1142        /// - Metal
1143        /// - Vulkan 1.2+ (or VK_EXT_descriptor_indexing)'s `shaderUniformBufferArrayNonUniformIndexing` feature)
1144        ///
1145        /// This is a native only feature.
1146        const UNIFORM_BUFFER_BINDING_ARRAYS = 1 << 47;
1147
1148        /// Enables mesh shaders and task shaders in mesh shader pipelines. This extension does NOT imply support for
1149        /// compiling mesh shaders at runtime.
1150        ///
1151        /// Supported platforms:
1152        /// - Vulkan (with [VK_EXT_mesh_shader](https://registry.khronos.org/vulkan/specs/latest/man/html/VK_EXT_mesh_shader.html))
1153        /// - DX12
1154        /// - Metal
1155        ///
1156        /// Naga is only supported on vulkan. On other platforms you will have to use passthrough shaders.
1157        ///
1158        /// It is recommended to use [`Device::create_shader_module_trusted`] with [`ShaderRuntimeChecks::unchecked()`]
1159        /// to avoid workgroup memory zero initialization, which can be expensive due to zero initialization being
1160        /// single-threaded currently.
1161        ///
1162        /// Some Mesa drivers including LLVMPIPE but not RADV fail to run the naga generated code.
1163        /// [This may be our bug and will be investigated.](https://github.com/gfx-rs/wgpu/issues/8727)
1164        /// However, due to the nature of the failure, the fact that it is unique, and the random changes
1165        /// that make it go away, this is believed to be a Mesa bug. See
1166        /// [this Mesa issue.](https://gitlab.freedesktop.org/mesa/mesa/-/issues/14376)
1167        ///
1168        /// This is a native only feature.
1169        ///
1170        /// [`Device::create_shader_module_trusted`]: https://docs.rs/wgpu/latest/wgpu/struct.Device.html#method.create_shader_module_trusted
1171        /// [`ShaderRuntimeChecks::unchecked()`]: crate::ShaderRuntimeChecks::unchecked
1172        const EXPERIMENTAL_MESH_SHADER = 1 << 48;
1173
1174        /// ***THIS IS EXPERIMENTAL:*** Features enabled by this may have
1175        /// major bugs in them and are expected to be subject to breaking changes, suggestions
1176        /// for the API exposed by this should be posted on [the ray-tracing issue](https://github.com/gfx-rs/wgpu/issues/6762)
1177        ///
1178        /// Allows for returning of the hit triangle's vertex position when tracing with an
1179        /// acceleration structure marked with [`AccelerationStructureFlags::ALLOW_RAY_HIT_VERTEX_RETURN`].
1180        ///
1181        /// Supported platforms:
1182        /// - Vulkan
1183        ///
1184        /// This is a native only feature
1185        ///
1186        /// [`AccelerationStructureFlags::ALLOW_RAY_HIT_VERTEX_RETURN`]: super::AccelerationStructureFlags::ALLOW_RAY_HIT_VERTEX_RETURN
1187        const EXPERIMENTAL_RAY_HIT_VERTEX_RETURN = 1 << 49;
1188
1189        /// Enables multiview in mesh shader pipelines
1190        ///
1191        /// Supported platforms:
1192        /// - Vulkan (with [VK_EXT_mesh_shader](https://registry.khronos.org/vulkan/specs/latest/man/html/VK_EXT_mesh_shader.html))
1193        ///
1194        /// Potential Platforms:
1195        /// - DX12
1196        /// - Metal
1197        ///
1198        /// This is a native only feature.
1199        const EXPERIMENTAL_MESH_SHADER_MULTIVIEW = 1 << 50;
1200
1201        /// Allows usage of additional vertex formats in [BlasTriangleGeometrySizeDescriptor::vertex_format]
1202        ///
1203        /// Supported platforms
1204        /// - Vulkan
1205        /// - DX12
1206        ///
1207        /// [BlasTriangleGeometrySizeDescriptor::vertex_format]: super::BlasTriangleGeometrySizeDescriptor
1208        const EXTENDED_ACCELERATION_STRUCTURE_VERTEX_FORMATS = 1 << 51;
1209
1210        /// Enables creating shaders from passthrough with reflection info (unsafe)
1211        ///
1212        /// Allows using [`Device::create_shader_module_passthrough`].
1213        /// Shader code isn't parsed or interpreted in any way. It is the user's
1214        /// responsibility to ensure the code and reflection (if passed) are correct.
1215        ///
1216        /// Supported platforms
1217        /// - Vulkan
1218        /// - DX12
1219        /// - Metal
1220        /// - WebGPU
1221        ///
1222        /// Ideally, in the future, all platforms will be supported. For more info, see
1223        /// [this comment](https://github.com/gfx-rs/wgpu/issues/3103#issuecomment-2833058367).
1224        ///
1225        #[doc = link_to_wgpu_docs!(["`Device::create_shader_module_passthrough`"]: "struct.Device.html#method.create_shader_module_passthrough")]
1226        const EXPERIMENTAL_PASSTHROUGH_SHADERS = 1 << 52;
1227
1228        /// Enables shader barycentric coordinates.
1229        ///
1230        /// Supported platforms:
1231        /// - Vulkan (with VK_KHR_fragment_shader_barycentric)
1232        /// - DX12 (with SM 6.1+)
1233        /// - Metal (with MSL 2.2+)
1234        ///
1235        /// This is a native only feature.
1236        const SHADER_BARYCENTRICS = 1 << 53;
1237
1238        /// Enables using multiview where not all texture array layers are rendered to in a single render pass/render pipeline. Making
1239        /// use of this feature also requires enabling `Features::MULTIVIEW`.
1240        ///
1241        /// Supported platforms
1242        /// - Vulkan
1243        /// - DX12
1244        ///
1245        ///
1246        /// While metal supports this in theory, the behavior of `view_index` differs from vulkan and dx12 so the feature isn't exposed.
1247        const SELECTIVE_MULTIVIEW = 1 << 54;
1248
1249        /// Enables the use of point-primitive outputs from mesh shaders. Making use of this feature also requires enabling
1250        /// `Features::EXPERIMENTAL_MESH_SHADER`.
1251        ///
1252        /// Supported platforms
1253        /// - Vulkan
1254        /// - Metal
1255        ///
1256        /// This is a native only feature.
1257        const EXPERIMENTAL_MESH_SHADER_POINTS = 1 << 55;
1258
1259        /// Enables creating texture arrays that are also multisampled.
1260        ///
1261        /// Without this feature, you cannot create a texture that has both a `sample_count` higher
1262        /// than 1, and a `depth_or_array_layers` higher than 1.
1263        ///
1264        /// Supported platforms:
1265        /// - Vulkan (except VK_KHR_portability_subset if multisampleArrayImage is not available)
1266        const MULTISAMPLE_ARRAY = 1 << 56;
1267
1268        /// Enables cooperative matrix operations (also known as tensor cores on NVIDIA GPUs
1269        /// or simdgroup matrix operations on Apple GPUs).
1270        ///
1271        /// Cooperative matrices allow a workgroup to collectively load, store, and perform
1272        /// matrix multiply-accumulate operations on small tiles of data, enabling
1273        /// hardware-accelerated matrix math.
1274        ///
1275        /// **Current limitations:** The implementation currently only supports 8x8 f32 matrices.
1276        /// On Vulkan, support is determined by querying `vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR`
1277        /// for configurations matching 8x8x8 f32. Most Vulkan implementations (NVIDIA, AMD) primarily
1278        /// support f16 inputs at larger sizes (e.g., 16x16), so Vulkan support may be limited.
1279        ///
1280        /// Supported platforms:
1281        /// - Metal (with MSL 2.3+ and Apple7+/Mac2+, using simdgroup matrix operations)
1282        /// - Vulkan (with [VK_KHR_cooperative_matrix](https://registry.khronos.org/vulkan/specs/latest/man/html/VK_KHR_cooperative_matrix.html), if 8x8 f32 is supported)
1283        ///
1284        /// This is a native only feature.
1285        const EXPERIMENTAL_COOPERATIVE_MATRIX = 1 << 57;
1286
1287        /// Enables shader per-vertex attributes.
1288        ///
1289        /// Supported platforms:
1290        /// - Vulkan (with VK_KHR_fragment_shader_barycentric)
1291        ///
1292        /// This is a native only feature.
1293        const SHADER_PER_VERTEX = 1 << 58;
1294
1295        /// Enables shader `draw_index` builtin.
1296        ///
1297        /// Supported platforms:
1298        /// - GLES
1299        /// - Vulkan
1300        ///
1301        /// Potential platforms:
1302        /// - DX12
1303        /// - Metal
1304        ///
1305        /// This is a native only feature.
1306        const SHADER_DRAW_INDEX = 1 << 59;
1307    }
1308
1309    /// Features that are not guaranteed to be supported.
1310    ///
1311    /// These are part of the WebGPU standard. For all features, see [`Features`].
1312    ///
1313    /// If you want to use a feature, you need to first verify that the adapter supports
1314    /// the feature. If the adapter does not support the feature, requesting a device with it enabled
1315    /// will panic.
1316    ///
1317    /// Corresponds to [WebGPU `GPUFeatureName`](
1318    /// https://gpuweb.github.io/gpuweb/#enumdef-gpufeaturename).
1319    #[repr(transparent)]
1320    #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1321    #[cfg_attr(feature = "serde", serde(transparent))]
1322    #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
1323    pub struct FeaturesWebGPU features_webgpu {
1324        // API:
1325
1326        /// By default, polygon depth is clipped to 0-1 range before/during rasterization.
1327        /// Anything outside of that range is rejected, and respective fragments are not touched.
1328        ///
1329        /// With this extension, we can disabling clipping. That allows
1330        /// shadow map occluders to be rendered into a tighter depth range.
1331        ///
1332        /// Supported platforms:
1333        /// - desktops
1334        /// - some mobile chips
1335        ///
1336        /// This is a web and native feature.
1337        const DEPTH_CLIP_CONTROL = WEBGPU_FEATURE_DEPTH_CLIP_CONTROL;
1338
1339        /// Allows for explicit creation of textures of format [`TextureFormat::Depth32FloatStencil8`]
1340        ///
1341        /// Supported platforms:
1342        /// - Vulkan (mostly)
1343        /// - DX12
1344        /// - Metal
1345        /// - OpenGL
1346        ///
1347        /// This is a web and native feature.
1348        ///
1349        /// [`TextureFormat::Depth32FloatStencil8`]: super::TextureFormat::Depth32FloatStencil8
1350        const DEPTH32FLOAT_STENCIL8 = WEBGPU_FEATURE_DEPTH32FLOAT_STENCIL8;
1351
1352        /// Enables BCn family of compressed textures. All BCn textures use 4x4 pixel blocks
1353        /// with 8 or 16 bytes per block.
1354        ///
1355        /// Compressed textures sacrifice some quality in exchange for significantly reduced
1356        /// bandwidth usage.
1357        ///
1358        /// Support for this feature guarantees availability of [`TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING`] for BCn formats.
1359        /// [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] may enable additional usages.
1360        ///
1361        /// This feature guarantees availability of sliced-3d textures for BC formats when combined with TEXTURE_COMPRESSION_BC_SLICED_3D.
1362        ///
1363        /// Supported Platforms:
1364        /// - desktops
1365        /// - Mobile (All Apple9 and some Apple7 and Apple8 devices)
1366        ///
1367        /// This is a web and native feature.
1368        const TEXTURE_COMPRESSION_BC = WEBGPU_FEATURE_TEXTURE_COMPRESSION_BC;
1369
1370
1371        /// Allows the 3d dimension for textures with BC compressed formats.
1372        ///
1373        /// This feature must be used in combination with TEXTURE_COMPRESSION_BC to enable 3D textures with BC compression.
1374        /// It does not enable the BC formats by itself.
1375        ///
1376        /// Supported Platforms:
1377        /// - desktops
1378        /// - Mobile (All Apple9 and some Apple7 and Apple8 devices)
1379        ///
1380        /// This is a web and native feature.
1381        const TEXTURE_COMPRESSION_BC_SLICED_3D = WEBGPU_FEATURE_TEXTURE_COMPRESSION_BC_SLICED_3D;
1382
1383        /// Enables ETC family of compressed textures. All ETC textures use 4x4 pixel blocks.
1384        /// ETC2 RGB and RGBA1 are 8 bytes per block. RTC2 RGBA8 and EAC are 16 bytes per block.
1385        ///
1386        /// Compressed textures sacrifice some quality in exchange for significantly reduced
1387        /// bandwidth usage.
1388        ///
1389        /// Support for this feature guarantees availability of [`TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING`] for ETC2 formats.
1390        /// [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] may enable additional usages.
1391        ///
1392        /// Supported Platforms:
1393        /// - Vulkan on Intel
1394        /// - Mobile (some)
1395        ///
1396        /// This is a web and native feature.
1397        const TEXTURE_COMPRESSION_ETC2 = WEBGPU_FEATURE_TEXTURE_COMPRESSION_ETC2;
1398
1399        /// Enables ASTC family of compressed textures. ASTC textures use pixel blocks varying from 4x4 to 12x12.
1400        /// Blocks are always 16 bytes.
1401        ///
1402        /// Compressed textures sacrifice some quality in exchange for significantly reduced
1403        /// bandwidth usage.
1404        ///
1405        /// Support for this feature guarantees availability of [`TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING`] for ASTC formats with Unorm/UnormSrgb channel type.
1406        /// [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] may enable additional usages.
1407        ///
1408        /// This feature does not guarantee availability of sliced 3d textures for ASTC formats.
1409        /// If available, 3d support can be enabled by TEXTURE_COMPRESSION_ASTC_SLICED_3D feature.
1410        ///
1411        /// Supported Platforms:
1412        /// - Vulkan on Intel
1413        /// - Mobile (some)
1414        ///
1415        /// This is a web and native feature.
1416        const TEXTURE_COMPRESSION_ASTC = WEBGPU_FEATURE_TEXTURE_COMPRESSION_ASTC;
1417
1418
1419        /// Allows the 3d dimension for textures with ASTC compressed formats.
1420        ///
1421        /// This feature must be used in combination with TEXTURE_COMPRESSION_ASTC to enable 3D textures with ASTC compression.
1422        /// It does not enable the ASTC formats by itself.
1423        ///
1424        /// Supported Platforms:
1425        /// - Vulkan (some)
1426        /// - Metal on Apple3+
1427        /// - OpenGL/WebGL (some)
1428        ///
1429        /// Not Supported:
1430        /// - DX12
1431        ///
1432        /// This is a web and native feature.
1433        const TEXTURE_COMPRESSION_ASTC_SLICED_3D = WEBGPU_FEATURE_TEXTURE_COMPRESSION_ASTC_SLICED_3D;
1434
1435        /// Enables use of Timestamp Queries. These queries tell the current gpu timestamp when
1436        /// all work before the query is finished.
1437        ///
1438        /// This feature allows the use of
1439        /// - [`RenderPassDescriptor::timestamp_writes`]
1440        /// - [`ComputePassDescriptor::timestamp_writes`]
1441        /// to write out timestamps.
1442        ///
1443        /// For arbitrary timestamp write commands on encoders refer to [`Features::TIMESTAMP_QUERY_INSIDE_ENCODERS`].
1444        /// For arbitrary timestamp write commands on passes refer to [`Features::TIMESTAMP_QUERY_INSIDE_PASSES`].
1445        ///
1446        /// They must be resolved using [`CommandEncoder::resolve_query_set`] into a buffer,
1447        /// then the result must be multiplied by the timestamp period [`Queue::get_timestamp_period`]
1448        /// to get the timestamp in nanoseconds. Multiple timestamps can then be diffed to get the
1449        /// time for operations between them to finish.
1450        ///
1451        /// Supported Platforms:
1452        /// - Vulkan
1453        /// - DX12
1454        /// - Metal
1455        ///
1456        /// This is a web and native feature.
1457        ///
1458        #[doc = link_to_wgpu_docs!(["`RenderPassDescriptor::timestamp_writes`"]: "struct.RenderPassDescriptor.html#structfield.timestamp_writes")]
1459        #[doc = link_to_wgpu_docs!(["`ComputePassDescriptor::timestamp_writes`"]: "struct.ComputePassDescriptor.html#structfield.timestamp_writes")]
1460        #[doc = link_to_wgpu_docs!(["`CommandEncoder::resolve_query_set`"]: "struct.CommandEncoder.html#method.resolve_query_set")]
1461        #[doc = link_to_wgpu_docs!(["`Queue::get_timestamp_period`"]: "struct.Queue.html#method.get_timestamp_period")]
1462        const TIMESTAMP_QUERY = WEBGPU_FEATURE_TIMESTAMP_QUERY;
1463
1464        /// Allows non-zero value for the `first_instance` member in indirect draw calls.
1465        ///
1466        /// If this feature is not enabled, and the `first_instance` member is non-zero, the behavior may be:
1467        /// - The draw call is ignored.
1468        /// - The draw call is executed as if the `first_instance` is zero.
1469        /// - The draw call is executed with the correct `first_instance` value.
1470        ///
1471        /// Supported Platforms:
1472        /// - Vulkan (mostly)
1473        /// - DX12
1474        /// - Metal on Apple3+ or Mac1+
1475        /// - OpenGL (Desktop 4.2+ with ARB_shader_draw_parameters only)
1476        ///
1477        /// Not Supported:
1478        /// - OpenGL ES / WebGL
1479        ///
1480        /// This is a web and native feature.
1481        const INDIRECT_FIRST_INSTANCE = WEBGPU_FEATURE_INDIRECT_FIRST_INSTANCE;
1482
1483        /// Allows shaders to use 16-bit floating point types. You may use them uniform buffers,
1484        /// storage buffers, and local variables. You may not use them in immediates.
1485        ///
1486        /// In order to use this in WGSL shaders, you must add `enable f16;` to the top of your shader,
1487        /// before any global items.
1488        ///
1489        /// Supported Platforms:
1490        /// - Vulkan
1491        /// - Metal
1492        /// - DX12
1493        ///
1494        /// This is a web and native feature.
1495        const SHADER_F16 = WEBGPU_FEATURE_SHADER_F16;
1496
1497        /// Allows for usage of textures of format [`TextureFormat::Rg11b10Ufloat`] as a render target
1498        ///
1499        /// Supported platforms:
1500        /// - Vulkan
1501        /// - DX12
1502        /// - Metal
1503        ///
1504        /// This is a web and native feature.
1505        ///
1506        /// [`TextureFormat::Rg11b10Ufloat`]: super::TextureFormat::Rg11b10Ufloat
1507        const RG11B10UFLOAT_RENDERABLE = WEBGPU_FEATURE_RG11B10UFLOAT_RENDERABLE;
1508
1509        /// Allows the [`TextureUsages::STORAGE_BINDING`] usage on textures with format [`TextureFormat::Bgra8Unorm`]
1510        ///
1511        /// Supported Platforms:
1512        /// - Vulkan
1513        /// - DX12
1514        /// - Metal
1515        ///
1516        /// This is a web and native feature.
1517        ///
1518        /// [`TextureFormat::Bgra8Unorm`]: super::TextureFormat::Bgra8Unorm
1519        /// [`TextureUsages::STORAGE_BINDING`]: super::TextureUsages::STORAGE_BINDING
1520        const BGRA8UNORM_STORAGE = WEBGPU_FEATURE_BGRA8UNORM_STORAGE;
1521
1522
1523        /// Allows textures with formats "r32float", "rg32float", and "rgba32float" to be filterable.
1524        ///
1525        /// Supported Platforms:
1526        /// - Vulkan (mainly on Desktop GPUs)
1527        /// - DX12
1528        /// - Metal on macOS or Apple9+ GPUs, optional on iOS/iPadOS with Apple7/8 GPUs
1529        /// - GL with one of `GL_ARB_color_buffer_float`/`GL_EXT_color_buffer_float`/`OES_texture_float_linear`
1530        ///
1531        /// This is a web and native feature.
1532        const FLOAT32_FILTERABLE = WEBGPU_FEATURE_FLOAT32_FILTERABLE;
1533
1534        /// Allows textures with formats "r32float", "rg32float", and "rgba32float" to be blendable.
1535        ///
1536        /// Supported Platforms:
1537        /// - Vulkan
1538        const FLOAT32_BLENDABLE = WEBGPU_FEATURE_FLOAT32_BLENDABLE;
1539
1540        /// Allows two outputs from a shader to be used for blending.
1541        /// Note that dual-source blending doesn't support multiple render targets.
1542        ///
1543        /// For more info see the OpenGL ES extension GL_EXT_blend_func_extended.
1544        ///
1545        /// Supported platforms:
1546        /// - OpenGL ES (with GL_EXT_blend_func_extended)
1547        /// - Metal (with MSL 1.2+)
1548        /// - Vulkan (with dualSrcBlend)
1549        /// - DX12
1550        ///
1551        /// This is a web and native feature.
1552        const DUAL_SOURCE_BLENDING = WEBGPU_FEATURE_DUAL_SOURCE_BLENDING;
1553
1554        /// Allows the use of `@builtin(clip_distances)` in WGSL.
1555        ///
1556        /// Supported platforms:
1557        /// - Vulkan (mainly on Desktop GPUs)
1558        /// - GL (Desktop or `GL_EXT_clip_cull_distance`)
1559        ///
1560        /// This is a web and native feature.
1561        const CLIP_DISTANCES = WEBGPU_FEATURE_CLIP_DISTANCES;
1562
1563        /// Allows the use of immediate data: small, fast bits of memory that can be updated
1564        /// inside a [`RenderPass`].
1565        ///
1566        /// Allows the user to call [`RenderPass::set_immediates`], provide a non-zero immediate data size
1567        /// to [`PipelineLayoutDescriptor`], and provide a non-zero limit to [`Limits::max_immediate_size`].
1568        ///
1569        /// A block of immediate data can be declared in WGSL with `var<immediate>`:
1570        ///
1571        /// ```rust,ignore
1572        /// struct Immediates { example: f32, }
1573        /// var<immediate> c: Immediates;
1574        /// ```
1575        ///
1576        /// In GLSL, this corresponds to `layout(immediates) uniform Name {..}`.
1577        ///
1578        /// Supported platforms:
1579        /// - DX12
1580        /// - Vulkan
1581        /// - Metal
1582        /// - OpenGL (emulated with uniforms)
1583        ///
1584        /// WebGPU support is currently a proposal and will be available in browsers in the future.
1585        ///
1586        /// This is a web and native feature.
1587        ///
1588        #[doc = link_to_wgpu_item!(struct RenderPass)]
1589        #[doc = link_to_wgpu_item!(struct PipelineLayoutDescriptor)]
1590        #[doc = link_to_wgpu_docs!(["`RenderPass::set_immediates`"]: "struct.RenderPass.html#method.set_immediates")]
1591        /// [`Limits::max_immediate_size`]: super::Limits
1592        const IMMEDIATES = WEBGPU_FEATURE_IMMEDIATES;
1593    }
1594}
1595
1596impl Features {
1597    /// Mask of all features which are part of the upstream WebGPU standard.
1598    #[must_use]
1599    pub const fn all_webgpu_mask() -> Self {
1600        Self::from_bits_truncate(FeatureBits([
1601            FeaturesWGPU::empty().bits(),
1602            FeaturesWebGPU::all().bits(),
1603        ]))
1604    }
1605
1606    /// Mask of all features that are only available when targeting native (not web).
1607    #[must_use]
1608    pub const fn all_native_mask() -> Self {
1609        Self::from_bits_truncate(FeatureBits([
1610            FeaturesWGPU::all().bits(),
1611            FeaturesWebGPU::empty().bits(),
1612        ]))
1613    }
1614
1615    /// Mask of all features which are experimental.
1616    #[must_use]
1617    pub const fn all_experimental_mask() -> Self {
1618        Self::from_bits_truncate(FeatureBits([
1619            FeaturesWGPU::EXPERIMENTAL_MESH_SHADER.bits()
1620                | FeaturesWGPU::EXPERIMENTAL_MESH_SHADER_MULTIVIEW.bits()
1621                | FeaturesWGPU::EXPERIMENTAL_MESH_SHADER_POINTS.bits()
1622                | FeaturesWGPU::EXPERIMENTAL_RAY_QUERY.bits()
1623                | FeaturesWGPU::EXPERIMENTAL_RAY_HIT_VERTEX_RETURN.bits()
1624                | FeaturesWGPU::EXPERIMENTAL_PASSTHROUGH_SHADERS.bits()
1625                | FeaturesWGPU::EXPERIMENTAL_COOPERATIVE_MATRIX.bits(),
1626            FeaturesWebGPU::empty().bits(),
1627        ]))
1628    }
1629
1630    /// Vertex formats allowed for creating and building BLASes
1631    #[must_use]
1632    pub fn allowed_vertex_formats_for_blas(&self) -> Vec<VertexFormat> {
1633        let mut formats = Vec::new();
1634        if self.intersects(Self::EXPERIMENTAL_RAY_QUERY) {
1635            formats.push(VertexFormat::Float32x3);
1636        }
1637        if self.contains(Self::EXTENDED_ACCELERATION_STRUCTURE_VERTEX_FORMATS) {
1638            formats.push(VertexFormat::Float32x2);
1639            formats.push(VertexFormat::Float16x2);
1640            formats.push(VertexFormat::Float16x4);
1641            formats.push(VertexFormat::Snorm16x2);
1642            formats.push(VertexFormat::Snorm16x4);
1643        }
1644        formats
1645    }
1646}
1647
1648#[cfg(test)]
1649mod tests {
1650    use crate::{Features, FeaturesWGPU, FeaturesWebGPU};
1651
1652    #[cfg(feature = "serde")]
1653    #[test]
1654    fn check_hex() {
1655        use crate::FeatureBits;
1656
1657        use bitflags::{
1658            parser::{ParseHex as _, WriteHex as _},
1659            Bits as _,
1660        };
1661
1662        let mut hex = alloc::string::String::new();
1663        FeatureBits::ALL.write_hex(&mut hex).unwrap();
1664        assert_eq!(
1665            FeatureBits::parse_hex(hex.as_str()).unwrap(),
1666            FeatureBits::ALL
1667        );
1668
1669        hex.clear();
1670        FeatureBits::EMPTY.write_hex(&mut hex).unwrap();
1671        assert_eq!(
1672            FeatureBits::parse_hex(hex.as_str()).unwrap(),
1673            FeatureBits::EMPTY
1674        );
1675
1676        for feature in Features::FLAGS {
1677            hex.clear();
1678            feature.value().bits().write_hex(&mut hex).unwrap();
1679            assert_eq!(
1680                FeatureBits::parse_hex(hex.as_str()).unwrap(),
1681                feature.value().bits(),
1682                "{hex}"
1683            );
1684        }
1685    }
1686
1687    #[test]
1688    fn check_features_display() {
1689        use alloc::format;
1690
1691        let feature = Features::CLEAR_TEXTURE;
1692        assert_eq!(format!("{feature}"), "CLEAR_TEXTURE");
1693
1694        let feature = Features::CLEAR_TEXTURE | Features::BGRA8UNORM_STORAGE;
1695        assert_eq!(format!("{feature}"), "CLEAR_TEXTURE | BGRA8UNORM_STORAGE");
1696    }
1697
1698    #[test]
1699    fn check_features_bits() {
1700        let bits = Features::all().bits();
1701        assert_eq!(Features::from_bits_retain(bits), Features::all());
1702
1703        let bits = Features::empty().bits();
1704        assert_eq!(Features::from_bits_retain(bits), Features::empty());
1705
1706        for feature in Features::FLAGS {
1707            let bits = feature.value().bits();
1708            assert_eq!(Features::from_bits_retain(bits), *feature.value());
1709        }
1710
1711        let bits = Features::all().bits();
1712        assert_eq!(Features::from_bits_truncate(bits), Features::all());
1713
1714        let bits = Features::empty().bits();
1715        assert_eq!(Features::from_bits_truncate(bits), Features::empty());
1716
1717        for feature in Features::FLAGS {
1718            let bits = feature.value().bits();
1719            assert_eq!(Features::from_bits_truncate(bits), *feature.value());
1720        }
1721
1722        let bits = Features::all().bits();
1723        assert_eq!(Features::from_bits(bits).unwrap(), Features::all());
1724
1725        let bits = Features::empty().bits();
1726        assert_eq!(Features::from_bits(bits).unwrap(), Features::empty());
1727
1728        for feature in Features::FLAGS {
1729            let bits = feature.value().bits();
1730            assert_eq!(Features::from_bits(bits).unwrap(), *feature.value());
1731        }
1732    }
1733
1734    #[test]
1735    fn create_features_from_parts() {
1736        let features: Features = FeaturesWGPU::TEXTURE_ATOMIC.into();
1737        assert_eq!(features, Features::TEXTURE_ATOMIC);
1738
1739        let features: Features = FeaturesWebGPU::TIMESTAMP_QUERY.into();
1740        assert_eq!(features, Features::TIMESTAMP_QUERY);
1741
1742        let features: Features = Features::from(FeaturesWGPU::TEXTURE_ATOMIC)
1743            | Features::from(FeaturesWebGPU::TIMESTAMP_QUERY);
1744        assert_eq!(
1745            features,
1746            Features::TEXTURE_ATOMIC | Features::TIMESTAMP_QUERY
1747        );
1748        assert_eq!(
1749            features,
1750            Features::from_internal_flags(
1751                FeaturesWGPU::TEXTURE_ATOMIC,
1752                FeaturesWebGPU::TIMESTAMP_QUERY
1753            )
1754        );
1755    }
1756
1757    #[test]
1758    fn experimental_features_part_of_experimental_mask() {
1759        for (name, feature) in Features::all().iter_names() {
1760            let prefixed_with_experimental = name.starts_with("EXPERIMENTAL_");
1761            let in_experimental_mask = Features::all_experimental_mask().contains(feature);
1762            assert_eq!(in_experimental_mask, prefixed_with_experimental);
1763        }
1764    }
1765}