Skip to main content

wgpu_types/
features.rs

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