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)]
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 // Bit 25 is available.
691
692 /// Enables multiview render passes and `builtin(view_index)` in vertex/mesh shaders.
693 ///
694 /// Supported platforms:
695 /// - Vulkan
696 /// - Metal
697 /// - DX12
698 /// - OpenGL (web only)
699 ///
700 /// This is a native only feature.
701 #[name("wgpu-multiview", "multiview")]
702 const MULTIVIEW = 1 << 26;
703 /// Enables using 64-bit types for vertex attributes.
704 ///
705 /// Requires SHADER_FLOAT64.
706 ///
707 /// Supported Platforms: N/A
708 ///
709 /// This is a native only feature.
710 #[name("wgpu-vertex-attribute-64-bit", "vertex-attribute-64-bit")]
711 const VERTEX_ATTRIBUTE_64BIT = 1 << 27;
712 /// Enables image atomic fetch add, and, xor, or, min, and max for R32Uint and R32Sint textures.
713 ///
714 /// Supported platforms:
715 /// - Vulkan
716 /// - DX12
717 /// - Metal (with MSL 3.1+)
718 ///
719 /// This is a native only feature.
720 #[name("wgpu-texture-atomic")]
721 const TEXTURE_ATOMIC = 1 << 28;
722 /// Allows for creation of textures of format [`TextureFormat::NV12`]
723 ///
724 /// Supported platforms:
725 /// - DX12
726 /// - Vulkan
727 /// - Metal (simulated)
728 ///
729 /// This is a native only feature.
730 ///
731 /// [`TextureFormat::NV12`]: super::TextureFormat::NV12
732 #[name("wgpu-texture-format-nv12")]
733 const TEXTURE_FORMAT_NV12 = 1 << 29;
734 /// Allows for creation of textures of format [`TextureFormat::P010`]
735 ///
736 /// Supported platforms:
737 /// - DX12
738 /// - Vulkan
739 /// - Metal
740 ///
741 /// This is a native only feature.
742 ///
743 /// [`TextureFormat::P010`]: super::TextureFormat::P010
744 #[name("wgpu-texture-format-p010")]
745 const TEXTURE_FORMAT_P010 = 1 << 30;
746
747 /// Allows for the creation and usage of `ExternalTexture`s, and bind
748 /// group layouts containing external texture `BindingType`s.
749 ///
750 /// Conceptually this should really be a [`crate::DownlevelFlags`] as
751 /// it corresponds to WebGPU's [`GPUExternalTexture`](
752 /// https://www.w3.org/TR/webgpu/#gpuexternaltexture).
753 /// However, the implementation is currently in-progress, and until it
754 /// is complete we do not want applications to ignore adapters due to
755 /// a missing downlevel flag, when they may not require this feature at
756 /// all.
757 ///
758 /// Supported platforms:
759 /// - DX12
760 /// - Metal
761 #[name("wgpu-external-texture", "external-texture")]
762 const EXTERNAL_TEXTURE = 1 << 31;
763
764 // Shader:
765
766 /// ***THIS IS EXPERIMENTAL:*** Features enabled by this may have
767 /// major bugs in it and are expected to be subject to breaking changes, suggestions
768 /// for the API exposed by this should be posted on [the ray-tracing issue](https://github.com/gfx-rs/wgpu/issues/1040)
769 ///
770 /// Allows for the creation of ray-tracing queries within shaders.
771 ///
772 /// Supported platforms:
773 /// - Vulkan
774 ///
775 /// This is a native-only feature.
776 #[name("wgpu-ray-query")]
777 const EXPERIMENTAL_RAY_QUERY = 1 << 32;
778 /// Enables 64-bit floating point types in SPIR-V shaders.
779 ///
780 /// Note: even when supported by GPU hardware, 64-bit floating point operations are
781 /// frequently between 16 and 64 _times_ slower than equivalent operations on 32-bit floats.
782 ///
783 /// Supported Platforms:
784 /// - Vulkan
785 ///
786 /// This is a native only feature.
787 #[name("wgpu-shader-f64", "shader-f64")]
788 const SHADER_F64 = 1 << 33;
789 /// Allows shaders to use `i16` and `u16` 16-bit integer types.
790 ///
791 /// Requires `enable wgpu_int16;` in WGSL shaders.
792 ///
793 /// Supported platforms:
794 /// - Vulkan (with `shaderInt16` and `VK_KHR_16bit_storage`)
795 /// - Metal (always available)
796 /// - DX12 (with `Native16BitShaderOpsSupported`, SM 6.2+)
797 ///
798 /// This is a native only feature.
799 #[name("wgpu-shader-i16", "shader-i16")]
800 const SHADER_I16 = 1 << 34;
801
802 // Bit 35 is available.
803
804 /// Allows shaders to use the `early_depth_test` attribute.
805 ///
806 /// The attribute is applied to the fragment shader entry point. It can be used in two
807 /// ways:
808 ///
809 /// 1. Force early depth/stencil tests:
810 ///
811 /// - `@early_depth_test(force)` (WGSL)
812 ///
813 /// - `layout(early_fragment_tests) in;` (GLSL)
814 ///
815 /// - `[[early_fragment_tests]]` (MSL 1.2+)
816 ///
817 /// - `[earlydepthstencil]` (HLSL)
818 ///
819 /// 2. Provide a conservative depth specifier that allows an additional early
820 /// depth test under certain conditions:
821 ///
822 /// - `@early_depth_test(greater_equal/less_equal/unchanged)` (WGSL)
823 ///
824 /// - `layout(depth_<greater/less/unchanged>) out float gl_FragDepth;` (GLSL)
825 ///
826 /// - `[[depth(greater/less)]]` (MSL, any version)
827 ///
828 /// - `SV_Depth<GreaterEqual/LessEqual>` (HLSL), for pipelines that are not
829 /// multisampled. Multisampled pipelines use an unrestricted `SV_Depth` instead.
830 ///
831 /// See [`EarlyDepthTest`] for more details.
832 ///
833 /// Supported platforms:
834 /// - Vulkan
835 /// - Metal (with MSL 1.2+)
836 /// - DX12
837 /// - GLES 3.1+
838 ///
839 /// This is a native only feature.
840 ///
841 /// [`EarlyDepthTest`]: https://docs.rs/naga/latest/naga/ir/enum.EarlyDepthTest.html
842 #[name("wgpu-shader-early-depth-test", "shader-early-depth-test")]
843 const SHADER_EARLY_DEPTH_TEST = 1 << 36;
844 /// Allows shaders to use i64 and u64.
845 ///
846 /// Supported platforms:
847 /// - Vulkan
848 /// - DX12 (DXC only)
849 /// - Metal (with MSL 2.3+)
850 ///
851 /// This is a native only feature.
852 #[name("wgpu-shader-int64")]
853 const SHADER_INT64 = 1 << 37;
854 /// Allows compute and fragment shaders to use the subgroup operation
855 /// built-ins and perform subgroup operations (except barriers).
856 ///
857 /// Supported Platforms:
858 /// - Vulkan
859 /// - DX12
860 /// - Metal
861 /// - WebGPU
862 ///
863 /// The `subgroups` feature has been added to WebGPU, but there may be
864 /// differences between the standard and the `wgpu` implementation,
865 /// so it has not yet been moved to [`FeaturesWebGPU`].
866 /// See <https://github.com/gfx-rs/wgpu/issues/5555>.
867 ///
868 /// Because it is expected to move to the WebGPU feature set in the
869 /// not-too-distant future, the name omits the `wgpu-` prefix.
870 #[name("subgroups")]
871 const SUBGROUP = 1 << 38;
872 /// Allows vertex shaders to use the subgroup operation built-ins and
873 /// perform subgroup operations (except barriers).
874 ///
875 /// Supported Platforms:
876 /// - Vulkan
877 ///
878 /// This is a native only feature.
879 #[name("wgpu-subgroup-vertex")]
880 const SUBGROUP_VERTEX = 1 << 39;
881 /// Allows compute shaders to use the subgroup barrier.
882 ///
883 /// Requires [`Features::SUBGROUP`]. Without it, enables nothing.
884 ///
885 /// Supported Platforms:
886 /// - Vulkan
887 /// - Metal
888 ///
889 /// This is a native only feature.
890 #[name("wgpu-subgroup-barrier")]
891 const SUBGROUP_BARRIER = 1 << 40;
892 /// Allows the use of pipeline cache objects
893 ///
894 /// Supported platforms:
895 /// - Vulkan
896 ///
897 /// Unimplemented Platforms:
898 /// - DX12
899 /// - Metal
900 #[name("wgpu-pipeline-cache")]
901 const PIPELINE_CACHE = 1 << 41;
902 /// Allows shaders to use i64 and u64 atomic min and max.
903 ///
904 /// Supported platforms:
905 /// - Vulkan (with VK_KHR_shader_atomic_int64)
906 /// - DX12 (with SM 6.6+)
907 /// - Metal (with MSL 2.4+)
908 ///
909 /// This is a native only feature.
910 #[name("wgpu-shader-int64-atomic-min-max")]
911 const SHADER_INT64_ATOMIC_MIN_MAX = 1 << 42;
912 /// Allows shaders to use all i64 and u64 atomic operations.
913 ///
914 /// Supported platforms:
915 /// - Vulkan (with VK_KHR_shader_atomic_int64)
916 /// - DX12 (with SM 6.6+)
917 ///
918 /// This is a native only feature.
919 #[name("wgpu-shader-int64-atomic-all-ops")]
920 const SHADER_INT64_ATOMIC_ALL_OPS = 1 << 43;
921
922 // Bit 44 is available.
923
924 // Bit 45 is available.
925
926 /// Enables R64Uint image atomic min and max.
927 ///
928 /// Supported platforms:
929 /// - Vulkan (with VK_EXT_shader_image_atomic_int64)
930 /// - DX12 (with SM 6.6+)
931 /// - Metal (with MSL 3.1+; Apple8 on macOS or Apple9+)
932 ///
933 /// This is a native only feature.
934 #[name("wgpu-texture-int64-atomic")]
935 const TEXTURE_INT64_ATOMIC = 1 << 46;
936
937 /// Allows uniform buffers to be bound as binding arrays.
938 ///
939 /// This allows:
940 /// - Shaders to contain `var<uniform> buffer: binding_array<UniformBuffer>;`
941 /// - The `count` field of `BindGroupLayoutEntry`s with `Uniform` buffers, to be set to `Some`.
942 ///
943 /// Supported platforms:
944 /// - None (<https://github.com/gfx-rs/wgpu/issues/7149>)
945 ///
946 /// Potential Platforms:
947 /// - DX12
948 /// - Metal
949 /// - Vulkan 1.2+ (or VK_EXT_descriptor_indexing)'s `shaderUniformBufferArrayNonUniformIndexing` feature)
950 ///
951 /// This is a native only feature.
952 #[name("wgpu-uniform-buffer-binding-arrays", "uniform-buffer-binding-arrays")]
953 const UNIFORM_BUFFER_BINDING_ARRAYS = 1 << 47;
954
955 /// Enables mesh shaders and task shaders in mesh shader pipelines. This extension does NOT imply support for
956 /// compiling mesh shaders at runtime.
957 ///
958 /// Supported platforms:
959 /// - Vulkan (with [VK_EXT_mesh_shader](https://registry.khronos.org/vulkan/specs/latest/man/html/VK_EXT_mesh_shader.html))
960 /// - DX12
961 /// - Metal
962 ///
963 /// Naga is only supported on vulkan. On other platforms you will have to use passthrough shaders.
964 ///
965 /// It is recommended to use [`Device::create_shader_module_trusted`] with [`ShaderRuntimeChecks::unchecked()`]
966 /// to avoid workgroup memory zero initialization, which can be expensive due to zero initialization being
967 /// single-threaded currently.
968 ///
969 /// Some Mesa drivers including LLVMPIPE but not RADV fail to run the naga generated code.
970 /// [This may be our bug and will be investigated.](https://github.com/gfx-rs/wgpu/issues/8727)
971 /// However, due to the nature of the failure, the fact that it is unique, and the random changes
972 /// that make it go away, this is believed to be a Mesa bug. See
973 /// [this Mesa issue.](https://gitlab.freedesktop.org/mesa/mesa/-/issues/14376)
974 ///
975 /// This is a native only feature.
976 ///
977 /// [`Device::create_shader_module_trusted`]: https://docs.rs/wgpu/latest/wgpu/struct.Device.html#method.create_shader_module_trusted
978 /// [`ShaderRuntimeChecks::unchecked()`]: crate::ShaderRuntimeChecks::unchecked
979 #[name("wgpu-mesh-shader")]
980 const EXPERIMENTAL_MESH_SHADER = 1 << 48;
981
982 /// ***THIS IS EXPERIMENTAL:*** Features enabled by this may have
983 /// major bugs in them and are expected to be subject to breaking changes, suggestions
984 /// for the API exposed by this should be posted on [the ray-tracing issue](https://github.com/gfx-rs/wgpu/issues/6762)
985 ///
986 /// Allows for returning of the hit triangle's vertex position when tracing with an
987 /// acceleration structure marked with [`AccelerationStructureFlags::ALLOW_RAY_HIT_VERTEX_RETURN`].
988 ///
989 /// Supported platforms:
990 /// - Vulkan
991 ///
992 /// This is a native only feature
993 ///
994 /// [`AccelerationStructureFlags::ALLOW_RAY_HIT_VERTEX_RETURN`]: super::AccelerationStructureFlags::ALLOW_RAY_HIT_VERTEX_RETURN
995 #[name("wgpu-ray-hit-vertex-return")]
996 const EXPERIMENTAL_RAY_HIT_VERTEX_RETURN = 1 << 49;
997
998 /// Enables multiview in mesh shader pipelines
999 ///
1000 /// Supported platforms:
1001 /// - Vulkan (with [VK_EXT_mesh_shader](https://registry.khronos.org/vulkan/specs/latest/man/html/VK_EXT_mesh_shader.html))
1002 ///
1003 /// Potential Platforms:
1004 /// - DX12
1005 /// - Metal
1006 ///
1007 /// This is a native only feature.
1008 #[name("wgpu-mesh-shader-multiview")]
1009 const EXPERIMENTAL_MESH_SHADER_MULTIVIEW = 1 << 50;
1010
1011 /// Allows usage of additional vertex formats in [BlasTriangleGeometrySizeDescriptor::vertex_format]
1012 ///
1013 /// Supported platforms
1014 /// - Vulkan
1015 /// - DX12
1016 ///
1017 /// [BlasTriangleGeometrySizeDescriptor::vertex_format]: super::BlasTriangleGeometrySizeDescriptor
1018 #[name("wgpu-extended-acceleration-structure-vertex-formats")]
1019 const EXTENDED_ACCELERATION_STRUCTURE_VERTEX_FORMATS = 1 << 51;
1020
1021 /// Enables creating shaders from passthrough with reflection info (unsafe)
1022 ///
1023 /// Allows using [`Device::create_shader_module_passthrough`].
1024 /// Shader code isn't parsed or interpreted in any way. It is the user's
1025 /// responsibility to ensure the code and reflection (if passed) are correct.
1026 ///
1027 /// Supported platforms
1028 /// - Vulkan
1029 /// - DX12
1030 /// - Metal
1031 /// - WebGPU
1032 ///
1033 /// Ideally, in the future, all platforms will be supported. For more info, see
1034 /// [this comment](https://github.com/gfx-rs/wgpu/issues/3103#issuecomment-2833058367).
1035 ///
1036 #[doc = link_to_wgpu_docs!(["`Device::create_shader_module_passthrough`"]: "struct.Device.html#method.create_shader_module_passthrough")]
1037 #[name("wgpu-passthrough-shaders", "passthrough-shaders")]
1038 const PASSTHROUGH_SHADERS = 1 << 52;
1039
1040 /// Enables shader barycentric coordinates.
1041 ///
1042 /// Supported platforms:
1043 /// - Vulkan (with VK_KHR_fragment_shader_barycentric)
1044 /// - DX12 (with SM 6.1+)
1045 /// - Metal (with MSL 2.2+)
1046 ///
1047 /// This is a native only feature.
1048 #[name("wgpu-shader-barycentrics")]
1049 const SHADER_BARYCENTRICS = 1 << 53;
1050
1051 /// Enables using multiview where not all texture array layers are rendered to in a single render pass/render pipeline. Making
1052 /// use of this feature also requires enabling `Features::MULTIVIEW`.
1053 ///
1054 /// Supported platforms
1055 /// - Vulkan
1056 /// - DX12
1057 ///
1058 ///
1059 /// While metal supports this in theory, the behavior of `view_index` differs from vulkan and dx12 so the feature isn't exposed.
1060 #[name("wgpu-selective-multiview")]
1061 const SELECTIVE_MULTIVIEW = 1 << 54;
1062
1063 /// Enables the use of point-primitive outputs from mesh shaders. Making use of this feature also requires enabling
1064 /// `Features::EXPERIMENTAL_MESH_SHADER`.
1065 ///
1066 /// Supported platforms
1067 /// - Vulkan
1068 /// - Metal
1069 ///
1070 /// This is a native only feature.
1071 #[name("wgpu-mesh-shader-points")]
1072 const EXPERIMENTAL_MESH_SHADER_POINTS = 1 << 55;
1073
1074 /// Enables creating texture arrays that are also multisampled.
1075 ///
1076 /// Without this feature, you cannot create a texture that has both a `sample_count` higher
1077 /// than 1, and a `depth_or_array_layers` higher than 1.
1078 ///
1079 /// Supported platforms:
1080 /// - Vulkan (except VK_KHR_portability_subset if multisampleArrayImage is not available)
1081 /// - Metal (with macos 10.14+, ios 14.0+, tvos 16.0+, visionos 1.0+)
1082 #[name("wgpu-multisample-array")]
1083 const MULTISAMPLE_ARRAY = 1 << 56;
1084
1085 /// Enables cooperative matrix operations (also known as tensor cores on NVIDIA GPUs
1086 /// or simdgroup matrix operations on Apple GPUs).
1087 ///
1088 /// Cooperative matrices allow a workgroup to collectively load, store, and perform
1089 /// matrix multiply-accumulate operations on small tiles of data, enabling
1090 /// hardware-accelerated matrix math.
1091 ///
1092 /// **Current limitations:** The implementation currently only supports 8x8 f32 matrices.
1093 /// On Vulkan, support is determined by querying `vkGetPhysicalDeviceCooperativeMatrixPropertiesKHR`
1094 /// for configurations matching 8x8x8 f32. Most Vulkan implementations (NVIDIA, AMD) primarily
1095 /// support f16 inputs at larger sizes (e.g., 16x16), so Vulkan support may be limited.
1096 ///
1097 /// Supported platforms:
1098 /// - Metal (with MSL 2.3+ and Apple7+/Mac2+, using simdgroup matrix operations)
1099 /// - 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)
1100 ///
1101 /// This is a native only feature.
1102 #[name("wgpu-cooperative-matrix")]
1103 const EXPERIMENTAL_COOPERATIVE_MATRIX = 1 << 57;
1104
1105 /// Enables shader per-vertex attributes.
1106 ///
1107 /// Supported platforms:
1108 /// - Vulkan (with VK_KHR_fragment_shader_barycentric)
1109 ///
1110 /// This is a native only feature.
1111 #[name("wgpu-shader-per-vertex")]
1112 const SHADER_PER_VERTEX = 1 << 58;
1113
1114 /// Enables shader `draw_index` builtin.
1115 ///
1116 /// Supported platforms:
1117 /// - GLES
1118 /// - Vulkan
1119 ///
1120 /// Potential platforms:
1121 /// - DX12
1122 /// - Metal
1123 ///
1124 /// This is a native only feature.
1125 #[name("wgpu-shader-draw-index")]
1126 const SHADER_DRAW_INDEX = 1 << 59;
1127 /// Allows the user to create arrays of acceleration structures in shaders:
1128 ///
1129 /// ex.
1130 /// - `var tlas: binding_array<acceleration_structure, 10>` (WGSL)
1131 ///
1132 /// This capability allows them to exist and to be indexed by dynamically uniform values.
1133 ///
1134 /// Supported platforms:
1135 /// - DX12
1136 /// - Vulkan
1137 ///
1138 /// This is a native only feature.
1139 #[name("wgpu-acceleration-structure-binding-array")]
1140 const ACCELERATION_STRUCTURE_BINDING_ARRAY = 1 << 60;
1141
1142 /// Enables the `@coherent` memory decoration on storage buffer variables.
1143 ///
1144 /// Backend mapping:
1145 /// - Vulkan
1146 /// - DX12
1147 /// - Metal (3.2+)
1148 /// - GLES (ES 3.1+ / GL 4.3+)
1149 ///
1150 /// This is a native only feature.
1151 #[name("wgpu-memory-decoration-coherent")]
1152 const MEMORY_DECORATION_COHERENT = 1 << 61;
1153
1154 /// Enables the `@volatile` memory decoration on storage buffer variables.
1155 ///
1156 /// Backend mapping:
1157 /// - Vulkan
1158 /// - GLES (ES 3.1+ / GL 4.3+)
1159 ///
1160 /// This is a native only feature.
1161 #[name("wgpu-memory-decoration-volatile")]
1162 const MEMORY_DECORATION_VOLATILE = 1 << 62;
1163
1164 /// Allows [`TexelCopyBufferLayout::bytes_per_row`] in `copy_buffer_to_texture` and
1165 /// `copy_texture_to_buffer` to be any multiple of the texel block copy size, instead of a
1166 /// multiple of [`COPY_BYTES_PER_ROW_ALIGNMENT`] (256).
1167 ///
1168 /// Supported platforms:
1169 /// - Vulkan
1170 /// - Metal
1171 /// - GLES
1172 /// - DX12 (with `UnrestrictedBufferTextureCopyPitchSupported`)
1173 ///
1174 /// This is a native only feature.
1175 ///
1176 /// [`TexelCopyBufferLayout::bytes_per_row`]: crate::TexelCopyBufferLayout::bytes_per_row
1177 /// [`COPY_BYTES_PER_ROW_ALIGNMENT`]: crate::COPY_BYTES_PER_ROW_ALIGNMENT
1178 #[name("wgpu-unrestricted-bytes-per-row")]
1179 const UNRESTRICTED_BYTES_PER_ROW = 1 << 63;
1180
1181 // Search for "is available" to check for free bits earlier in the list.
1182 }
1183
1184 /// Features that are not guaranteed to be supported.
1185 ///
1186 /// These are part of the WebGPU standard. For all features, see [`Features`].
1187 ///
1188 /// If you want to use a feature, you need to first verify that the adapter supports
1189 /// the feature. If the adapter does not support the feature, requesting a device with it enabled
1190 /// will panic.
1191 ///
1192 /// Corresponds to [WebGPU `GPUFeatureName`](
1193 /// https://gpuweb.github.io/gpuweb/#enumdef-gpufeaturename).
1194 #[repr(transparent)]
1195 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1196 #[cfg_attr(feature = "serde", serde(transparent))]
1197 #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
1198 pub struct FeaturesWebGPU features_webgpu {
1199 // API:
1200
1201 /// Core features and limits that are guaranteed to be supported by all WebGPU specification-compliant adapters.
1202 /// This feature is always enabled on adapters for which [`crate::DownlevelCapabilities::is_webgpu_compliant`] returns `true`.
1203 ///
1204 /// This is a web and native feature.
1205 #[name("core-features-and-limits")]
1206 #[web(allow)]
1207 const CORE_FEATURES_AND_LIMITS = WEBGPU_FEATURE_CORE_FEATURES_AND_LIMITS;
1208
1209 /// By default, polygon depth is clipped to 0-1 range before/during rasterization.
1210 /// Anything outside of that range is rejected, and respective fragments are not touched.
1211 ///
1212 /// With this extension, we can disabling clipping. That allows
1213 /// shadow map occluders to be rendered into a tighter depth range.
1214 ///
1215 /// Supported platforms:
1216 /// - desktops
1217 /// - some mobile chips
1218 /// - WebGPU
1219 ///
1220 /// This is a web and native feature.
1221 #[name("depth-clip-control")]
1222 #[web(allow)]
1223 const DEPTH_CLIP_CONTROL = WEBGPU_FEATURE_DEPTH_CLIP_CONTROL;
1224
1225 /// Allows for explicit creation of textures of format [`TextureFormat::Depth32FloatStencil8`]
1226 ///
1227 /// Supported platforms:
1228 /// - Vulkan (mostly)
1229 /// - DX12
1230 /// - Metal
1231 /// - OpenGL
1232 /// - WebGPU
1233 ///
1234 /// This is a web and native feature.
1235 ///
1236 /// [`TextureFormat::Depth32FloatStencil8`]: super::TextureFormat::Depth32FloatStencil8
1237 #[name("depth32float-stencil8")]
1238 #[web(allow)]
1239 const DEPTH32FLOAT_STENCIL8 = WEBGPU_FEATURE_DEPTH32FLOAT_STENCIL8;
1240
1241 /// Enables BCn family of compressed textures. All BCn textures use 4x4 pixel blocks
1242 /// with 8 or 16 bytes per block.
1243 ///
1244 /// Compressed textures sacrifice some quality in exchange for significantly reduced
1245 /// bandwidth usage.
1246 ///
1247 /// Support for this feature guarantees availability of [`TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING`] for BCn formats.
1248 /// [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] may enable additional usages.
1249 ///
1250 /// This feature guarantees availability of sliced-3d textures for BC formats when combined with TEXTURE_COMPRESSION_BC_SLICED_3D.
1251 ///
1252 /// Supported Platforms:
1253 /// - desktops
1254 /// - Mobile (All Apple9 and some Apple7 and Apple8 devices)
1255 /// - WebGPU
1256 ///
1257 /// This is a web and native feature.
1258 #[name("texture-compression-bc")]
1259 #[web(allow)]
1260 const TEXTURE_COMPRESSION_BC = WEBGPU_FEATURE_TEXTURE_COMPRESSION_BC;
1261
1262
1263 /// Allows the 3d dimension for textures with BC compressed formats.
1264 ///
1265 /// This feature must be used in combination with TEXTURE_COMPRESSION_BC to enable 3D textures with BC compression.
1266 /// It does not enable the BC formats by itself.
1267 ///
1268 /// Supported Platforms:
1269 /// - desktops
1270 /// - Mobile (All Apple9 and some Apple7 and Apple8 devices)
1271 /// - WebGPU
1272 ///
1273 /// This is a web and native feature.
1274 #[name("texture-compression-bc-sliced-3d")]
1275 #[web(allow)]
1276 const TEXTURE_COMPRESSION_BC_SLICED_3D = WEBGPU_FEATURE_TEXTURE_COMPRESSION_BC_SLICED_3D;
1277
1278 /// Enables ETC family of compressed textures. All ETC textures use 4x4 pixel blocks.
1279 /// ETC2 RGB and RGBA1 are 8 bytes per block. RTC2 RGBA8 and EAC are 16 bytes per block.
1280 ///
1281 /// Compressed textures sacrifice some quality in exchange for significantly reduced
1282 /// bandwidth usage.
1283 ///
1284 /// Support for this feature guarantees availability of [`TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING`] for ETC2 formats.
1285 /// [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] may enable additional usages.
1286 ///
1287 /// Supported Platforms:
1288 /// - Vulkan on Intel
1289 /// - Mobile (some)
1290 /// - WebGPU
1291 ///
1292 /// This is a web and native feature.
1293 #[name("texture-compression-etc2")]
1294 #[web(allow)]
1295 const TEXTURE_COMPRESSION_ETC2 = WEBGPU_FEATURE_TEXTURE_COMPRESSION_ETC2;
1296
1297 /// Enables ASTC family of compressed textures. ASTC textures use pixel blocks varying from 4x4 to 12x12.
1298 /// Blocks are always 16 bytes.
1299 ///
1300 /// Compressed textures sacrifice some quality in exchange for significantly reduced
1301 /// bandwidth usage.
1302 ///
1303 /// Support for this feature guarantees availability of [`TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING`] for ASTC formats with Unorm/UnormSrgb channel type.
1304 /// [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] may enable additional usages.
1305 ///
1306 /// This feature does not guarantee availability of sliced 3d textures for ASTC formats.
1307 /// If available, 3d support can be enabled by TEXTURE_COMPRESSION_ASTC_SLICED_3D feature.
1308 ///
1309 /// Supported Platforms:
1310 /// - Vulkan on Intel
1311 /// - Mobile (some)
1312 /// - WebGPU
1313 ///
1314 /// This is a web and native feature.
1315 #[name("texture-compression-astc")]
1316 #[web(allow)]
1317 const TEXTURE_COMPRESSION_ASTC = WEBGPU_FEATURE_TEXTURE_COMPRESSION_ASTC;
1318
1319
1320 /// Allows the 3d dimension for textures with ASTC compressed formats.
1321 ///
1322 /// This feature must be used in combination with TEXTURE_COMPRESSION_ASTC to enable 3D textures with ASTC compression.
1323 /// It does not enable the ASTC formats by itself.
1324 ///
1325 /// Supported Platforms:
1326 /// - Vulkan (some)
1327 /// - Metal on Apple3+
1328 /// - OpenGL/WebGL (some)
1329 /// - WebGPU
1330 ///
1331 /// Not Supported:
1332 /// - DX12
1333 ///
1334 /// This is a web and native feature.
1335 #[name("texture-compression-astc-sliced-3d")]
1336 #[web(allow)]
1337 const TEXTURE_COMPRESSION_ASTC_SLICED_3D = WEBGPU_FEATURE_TEXTURE_COMPRESSION_ASTC_SLICED_3D;
1338
1339 /// Enables use of Timestamp Queries. These queries tell the current gpu timestamp when
1340 /// all work before the query is finished.
1341 ///
1342 /// This feature allows the use of
1343 /// - [`RenderPassDescriptor::timestamp_writes`]
1344 /// - [`ComputePassDescriptor::timestamp_writes`]
1345 /// to write out timestamps.
1346 ///
1347 /// For arbitrary timestamp write commands on encoders refer to [`Features::TIMESTAMP_QUERY_INSIDE_ENCODERS`].
1348 /// For arbitrary timestamp write commands on passes refer to [`Features::TIMESTAMP_QUERY_INSIDE_PASSES`].
1349 ///
1350 /// They must be resolved using [`CommandEncoder::resolve_query_set`] into a buffer,
1351 /// then the result must be multiplied by the timestamp period [`Queue::get_timestamp_period`]
1352 /// to get the timestamp in nanoseconds. Multiple timestamps can then be diffed to get the
1353 /// time for operations between them to finish.
1354 ///
1355 /// Supported Platforms:
1356 /// - Vulkan
1357 /// - DX12
1358 /// - Metal
1359 /// - OpenGL (with GL_ARB_timer_query)
1360 /// - WebGPU
1361 ///
1362 /// This is a web and native feature.
1363 ///
1364 #[doc = link_to_wgpu_docs!(["`RenderPassDescriptor::timestamp_writes`"]: "struct.RenderPassDescriptor.html#structfield.timestamp_writes")]
1365 #[doc = link_to_wgpu_docs!(["`ComputePassDescriptor::timestamp_writes`"]: "struct.ComputePassDescriptor.html#structfield.timestamp_writes")]
1366 #[doc = link_to_wgpu_docs!(["`CommandEncoder::resolve_query_set`"]: "struct.CommandEncoder.html#method.resolve_query_set")]
1367 #[doc = link_to_wgpu_docs!(["`Queue::get_timestamp_period`"]: "struct.Queue.html#method.get_timestamp_period")]
1368 #[name("timestamp-query")]
1369 #[web(allow)]
1370 const TIMESTAMP_QUERY = WEBGPU_FEATURE_TIMESTAMP_QUERY;
1371
1372 /// Allows non-zero value for the `first_instance` member in indirect draw calls.
1373 ///
1374 /// If this feature is not enabled, and the `first_instance` member is non-zero, the behavior may be:
1375 /// - The draw call is ignored.
1376 /// - The draw call is executed as if the `first_instance` is zero.
1377 /// - The draw call is executed with the correct `first_instance` value.
1378 ///
1379 /// Supported Platforms:
1380 /// - Vulkan (mostly)
1381 /// - DX12
1382 /// - Metal on Apple3+ or Mac1+
1383 /// - OpenGL (Desktop 4.2+ with ARB_shader_draw_parameters only)
1384 /// - WebGPU
1385 ///
1386 /// Not Supported:
1387 /// - OpenGL ES / WebGL
1388 ///
1389 /// This is a web and native feature.
1390 #[name("indirect-first-instance")]
1391 #[web(allow)]
1392 const INDIRECT_FIRST_INSTANCE = WEBGPU_FEATURE_INDIRECT_FIRST_INSTANCE;
1393
1394 /// Allows shaders to use 16-bit floating point types. You may use them uniform buffers,
1395 /// storage buffers, and local variables. You may not use them in immediates.
1396 ///
1397 /// In order to use this in WGSL shaders, you must add `enable f16;` to the top of your shader,
1398 /// before any global items.
1399 ///
1400 /// Supported Platforms:
1401 /// - Vulkan
1402 /// - Metal
1403 /// - DX12
1404 /// - WebGPU
1405 ///
1406 /// This is a web and native feature.
1407 #[name("shader-f16")]
1408 #[web(allow)]
1409 const SHADER_F16 = WEBGPU_FEATURE_SHADER_F16;
1410
1411 /// Allows for usage of textures of format [`TextureFormat::Rg11b10Ufloat`] as a render target
1412 ///
1413 /// Supported platforms:
1414 /// - Vulkan
1415 /// - DX12
1416 /// - Metal
1417 /// - WebGPU
1418 ///
1419 /// This is a web and native feature.
1420 ///
1421 /// [`TextureFormat::Rg11b10Ufloat`]: super::TextureFormat::Rg11b10Ufloat
1422 #[name("rg11b10ufloat-renderable")]
1423 #[web(allow)]
1424 const RG11B10UFLOAT_RENDERABLE = WEBGPU_FEATURE_RG11B10UFLOAT_RENDERABLE;
1425
1426 /// Allows the [`TextureUsages::STORAGE_BINDING`] usage on textures with format [`TextureFormat::Bgra8Unorm`]
1427 ///
1428 /// Supported Platforms:
1429 /// - Vulkan
1430 /// - DX12
1431 /// - Metal
1432 /// - WebGPU
1433 ///
1434 /// This is a web and native feature.
1435 ///
1436 /// [`TextureFormat::Bgra8Unorm`]: super::TextureFormat::Bgra8Unorm
1437 /// [`TextureUsages::STORAGE_BINDING`]: super::TextureUsages::STORAGE_BINDING
1438 #[name("bgra8unorm-storage")]
1439 #[web(allow)]
1440 const BGRA8UNORM_STORAGE = WEBGPU_FEATURE_BGRA8UNORM_STORAGE;
1441
1442
1443 /// Allows textures with formats "r32float", "rg32float", and "rgba32float" to be filterable.
1444 ///
1445 /// Supported Platforms:
1446 /// - Vulkan (mainly on Desktop GPUs)
1447 /// - DX12
1448 /// - Metal on macOS or Apple9+ GPUs, optional on iOS/iPadOS with Apple7/8 GPUs
1449 /// - GL with one of `GL_ARB_color_buffer_float`/`GL_EXT_color_buffer_float`/`OES_texture_float_linear`
1450 /// - WebGPU
1451 ///
1452 /// This is a web and native feature.
1453 #[name("float32-filterable")]
1454 #[web(allow)]
1455 const FLOAT32_FILTERABLE = WEBGPU_FEATURE_FLOAT32_FILTERABLE;
1456
1457 /// Allows textures with formats "r32float", "rg32float", and "rgba32float" to be blendable.
1458 ///
1459 /// Supported Platforms:
1460 /// - Vulkan
1461 /// - WebGPU
1462 #[name("float32-blendable")]
1463 #[web(allow)]
1464 const FLOAT32_BLENDABLE = WEBGPU_FEATURE_FLOAT32_BLENDABLE;
1465
1466 /// Allows two outputs from a shader to be used for blending.
1467 /// Note that dual-source blending doesn't support multiple render targets.
1468 ///
1469 /// For more info see the OpenGL ES extension GL_EXT_blend_func_extended.
1470 ///
1471 /// Supported platforms:
1472 /// - OpenGL ES (with GL_EXT_blend_func_extended)
1473 /// - Metal (with MSL 1.2+)
1474 /// - Vulkan (with dualSrcBlend)
1475 /// - DX12
1476 /// - WebGPU
1477 ///
1478 /// This is a web and native feature.
1479 #[name("dual-source-blending")]
1480 #[web(allow)]
1481 const DUAL_SOURCE_BLENDING = WEBGPU_FEATURE_DUAL_SOURCE_BLENDING;
1482
1483 /// Allows the use of `@builtin(clip_distances)` in WGSL.
1484 ///
1485 /// Supported platforms:
1486 /// - Vulkan (mainly on Desktop GPUs)
1487 /// - Metal
1488 /// - GL (Desktop or `GL_EXT_clip_cull_distance`)
1489 /// - WebGPU
1490 ///
1491 /// This is a web and native feature.
1492 #[name("clip-distances")]
1493 #[web(allow)]
1494 const CLIP_DISTANCES = WEBGPU_FEATURE_CLIP_DISTANCES;
1495
1496 /// Allows the use of immediate data: small, fast bits of memory that can be updated
1497 /// inside a [`RenderPass`].
1498 ///
1499 /// Allows the user to call [`RenderPass::set_immediates`], provide a non-zero immediate data size
1500 /// to [`PipelineLayoutDescriptor`], and provide a non-zero limit to [`Limits::max_immediate_size`].
1501 ///
1502 /// A block of immediate data can be declared in WGSL with `var<immediate>`:
1503 ///
1504 /// ```rust,ignore
1505 /// struct Immediates { example: f32, }
1506 /// var<immediate> c: Immediates;
1507 /// ```
1508 ///
1509 /// In GLSL, this corresponds to `layout(immediates) uniform Name {..}`.
1510 ///
1511 /// Supported platforms:
1512 /// - DX12
1513 /// - Vulkan
1514 /// - Metal
1515 /// - OpenGL (emulated with uniforms)
1516 /// - WebGPU
1517 ///
1518 /// WebGPU support is currently a proposal and will be available in browsers in the future.
1519 ///
1520 /// This is a web and native feature.
1521 ///
1522 #[doc = link_to_wgpu_item!(struct RenderPass)]
1523 #[doc = link_to_wgpu_item!(struct PipelineLayoutDescriptor)]
1524 #[doc = link_to_wgpu_docs!(["`RenderPass::set_immediates`"]: "struct.RenderPass.html#method.set_immediates")]
1525 /// [`Limits::max_immediate_size`]: super::Limits
1526 #[name("immediates")]
1527 #[web(allow)]
1528 const IMMEDIATES = WEBGPU_FEATURE_IMMEDIATES;
1529
1530 /// Enables `builtin(primitive_index)` in fragment shaders.
1531 ///
1532 /// Note: enables geometry processing for pipelines using the builtin.
1533 /// This may come with a significant performance impact on some hardware.
1534 /// Other pipelines are not affected.
1535 ///
1536 /// Supported platforms:
1537 /// - Vulkan (with geometryShader)
1538 /// - DX12
1539 /// - Metal (some)
1540 /// - OpenGL (some)
1541 ///
1542 /// This is a web and native feature. `primitive-index` is its
1543 /// WebGPU-defined name, and `shader-primitive-index` is accepted to
1544 /// remain compatible with previous wgpu behavior.
1545 #[name("primitive-index", "shader-primitive-index")]
1546 #[web(allow)]
1547 const PRIMITIVE_INDEX = WEBGPU_FEATURE_PRIMITIVE_INDEX;
1548
1549 /// Allows `TextureView`s to rearrange or replace the color components
1550 /// from texture's red/green/blue/alpha channels when used as a `TEXTURE_BINDING`.
1551 ///
1552 /// Supported platforms:
1553 /// - Vulkan
1554 /// - DX12
1555 /// - Metal on Apple2+ or Mac2+
1556 ///
1557 /// Not yet implemented:
1558 /// - OpenGL
1559 ///
1560 /// This is a web and native feature.
1561 #[name("texture-component-swizzle")]
1562 #[web(allow)]
1563 const TEXTURE_COMPONENT_SWIZZLE = WEBGPU_FEATURE_TEXTURE_COMPONENT_SWIZZLE;
1564 }
1565}
1566
1567impl Features {
1568 /// Construct a [`Features`] from separate [`FeaturesWGPU`] and [`FeaturesWebGPU`].
1569 ///
1570 /// This `const` constructor is also available as a `From` impl.
1571 pub const fn from_parts(wgpu: FeaturesWGPU, webgpu: FeaturesWebGPU) -> Self {
1572 Self::from_bits_retain(FeatureBits([wgpu.bits(), webgpu.bits()]))
1573 }
1574
1575 /// Mask of all features which are part of the upstream WebGPU standard.
1576 #[must_use]
1577 pub const fn all_webgpu_mask() -> Self {
1578 Self::from_parts(FeaturesWGPU::empty(), FeaturesWebGPU::all())
1579 }
1580
1581 /// Mask of all features that are only available when targeting native (not web).
1582 #[must_use]
1583 pub const fn all_native_mask() -> Self {
1584 Self::from_parts(FeaturesWGPU::all(), FeaturesWebGPU::empty())
1585 }
1586
1587 /// Mask of all features which are experimental.
1588 #[must_use]
1589 pub const fn all_experimental_mask() -> Self {
1590 Self::from_parts(
1591 FeaturesWGPU::from_bits_truncate(
1592 FeaturesWGPU::EXPERIMENTAL_MESH_SHADER.bits()
1593 | FeaturesWGPU::EXPERIMENTAL_MESH_SHADER_MULTIVIEW.bits()
1594 | FeaturesWGPU::EXPERIMENTAL_MESH_SHADER_POINTS.bits()
1595 | FeaturesWGPU::EXPERIMENTAL_RAY_QUERY.bits()
1596 | FeaturesWGPU::EXPERIMENTAL_RAY_HIT_VERTEX_RETURN.bits()
1597 | FeaturesWGPU::EXPERIMENTAL_COOPERATIVE_MATRIX.bits()
1598 | FeaturesWGPU::EXPERIMENTAL_RAY_TRACING_PIPELINES.bits(),
1599 ),
1600 FeaturesWebGPU::empty(),
1601 )
1602 }
1603
1604 /// Vertex formats allowed for creating and building BLASes
1605 #[must_use]
1606 pub fn allowed_vertex_formats_for_blas(&self) -> Vec<VertexFormat> {
1607 let mut formats = Vec::new();
1608 if self.intersects(Self::EXPERIMENTAL_RAY_QUERY | Self::EXPERIMENTAL_RAY_TRACING_PIPELINES)
1609 {
1610 formats.push(VertexFormat::Float32x3);
1611 }
1612 if self.contains(Self::EXTENDED_ACCELERATION_STRUCTURE_VERTEX_FORMATS) {
1613 formats.push(VertexFormat::Float32x2);
1614 formats.push(VertexFormat::Float16x2);
1615 formats.push(VertexFormat::Float16x4);
1616 formats.push(VertexFormat::Snorm16x2);
1617 formats.push(VertexFormat::Snorm16x4);
1618 }
1619 formats
1620 }
1621}
1622
1623#[cfg(test)]
1624mod tests {
1625 use crate::{Features, FeaturesWGPU, FeaturesWebGPU};
1626 use bitflags::{Flag, Flags};
1627
1628 #[cfg(feature = "serde")]
1629 #[test]
1630 fn check_hex() {
1631 use crate::FeatureBits;
1632
1633 use bitflags::{
1634 parser::{ParseHex as _, WriteHex as _},
1635 Bits as _,
1636 };
1637
1638 let mut hex = alloc::string::String::new();
1639 FeatureBits::ALL.write_hex(&mut hex).unwrap();
1640 assert_eq!(
1641 FeatureBits::parse_hex(hex.as_str()).unwrap(),
1642 FeatureBits::ALL
1643 );
1644
1645 hex.clear();
1646 FeatureBits::EMPTY.write_hex(&mut hex).unwrap();
1647 assert_eq!(
1648 FeatureBits::parse_hex(hex.as_str()).unwrap(),
1649 FeatureBits::EMPTY
1650 );
1651
1652 for feature in Features::FLAGS {
1653 hex.clear();
1654 feature.value().bits().write_hex(&mut hex).unwrap();
1655 assert_eq!(
1656 FeatureBits::parse_hex(hex.as_str()).unwrap(),
1657 feature.value().bits(),
1658 "{hex}"
1659 );
1660 }
1661 }
1662
1663 #[test]
1664 fn allowed_on_web_backend() {
1665 // Every WebGPU feature is currently allowed on the web backend,
1666 // as well as `subgroups`.
1667 assert_eq!(
1668 Features::ALLOWED_ON_WEB_BACKEND,
1669 Features::from_parts(FeaturesWGPU::SUBGROUP, FeaturesWebGPU::all()),
1670 );
1671 }
1672
1673 #[test]
1674 fn check_features_display() {
1675 use alloc::format;
1676
1677 let feature = Features::CLEAR_TEXTURE;
1678 assert_eq!(format!("{feature}"), "CLEAR_TEXTURE");
1679
1680 let feature = Features::CLEAR_TEXTURE | Features::BGRA8UNORM_STORAGE;
1681 assert_eq!(format!("{feature}"), "CLEAR_TEXTURE | BGRA8UNORM_STORAGE");
1682 }
1683
1684 #[test]
1685 fn check_features_bits() {
1686 let bits = Features::all().bits();
1687 assert_eq!(Features::from_bits_retain(bits), Features::all());
1688
1689 let bits = Features::empty().bits();
1690 assert_eq!(Features::from_bits_retain(bits), Features::empty());
1691
1692 for feature in Features::FLAGS {
1693 let bits = feature.value().bits();
1694 assert_eq!(Features::from_bits_retain(bits), *feature.value());
1695 }
1696
1697 let bits = FeaturesWebGPU::all().bits();
1698 assert_eq!(
1699 FeaturesWebGPU::from_bits_truncate(bits),
1700 FeaturesWebGPU::all()
1701 );
1702
1703 let bits = FeaturesWebGPU::empty().bits();
1704 assert_eq!(
1705 FeaturesWebGPU::from_bits_truncate(bits),
1706 FeaturesWebGPU::empty()
1707 );
1708
1709 for feature in FeaturesWebGPU::FLAGS {
1710 let bits = feature.value().bits();
1711 assert_eq!(FeaturesWebGPU::from_bits_truncate(bits), *feature.value());
1712 }
1713
1714 let bits = FeaturesWGPU::all().bits();
1715 assert_eq!(FeaturesWGPU::from_bits(bits).unwrap(), FeaturesWGPU::all());
1716
1717 let bits = FeaturesWGPU::empty().bits();
1718 assert_eq!(
1719 FeaturesWGPU::from_bits(bits).unwrap(),
1720 FeaturesWGPU::empty()
1721 );
1722
1723 for feature in FeaturesWGPU::FLAGS {
1724 let bits = feature.value().bits();
1725 assert_eq!(FeaturesWGPU::from_bits(bits).unwrap(), *feature.value());
1726 }
1727 }
1728
1729 #[test]
1730 fn features_names() {
1731 for feature in Features::FLAGS.iter().map(Flag::value).copied() {
1732 let Some(name) = feature.as_str() else {
1733 panic!("`.as_str()` for {feature:?} returned `None`");
1734 };
1735 assert_eq!(name.parse(), Ok(feature));
1736
1737 // Native-only features that are accepted without `wgpu-` prefix for backwards compatibility
1738 let prefix_backcompat_features = [
1739 Features::TEXTURE_FORMAT_16BIT_NORM,
1740 Features::TEXTURE_COMPRESSION_ASTC_HDR,
1741 Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES,
1742 Features::PIPELINE_STATISTICS_QUERY,
1743 Features::TIMESTAMP_QUERY_INSIDE_PASSES,
1744 Features::MAPPABLE_PRIMARY_BUFFERS,
1745 Features::TEXTURE_BINDING_ARRAY,
1746 Features::BUFFER_BINDING_ARRAY,
1747 Features::STORAGE_RESOURCE_BINDING_ARRAY,
1748 Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
1749 Features::STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
1750 Features::UNIFORM_BUFFER_BINDING_ARRAYS,
1751 Features::PARTIALLY_BOUND_BINDING_ARRAY,
1752 Features::MULTI_DRAW_INDIRECT_COUNT,
1753 Features::ADDRESS_MODE_CLAMP_TO_ZERO,
1754 Features::ADDRESS_MODE_CLAMP_TO_BORDER,
1755 Features::POLYGON_MODE_LINE,
1756 Features::POLYGON_MODE_POINT,
1757 Features::CONSERVATIVE_RASTERIZATION,
1758 Features::VERTEX_WRITABLE_STORAGE,
1759 Features::CLEAR_TEXTURE,
1760 Features::MULTIVIEW,
1761 Features::VERTEX_ATTRIBUTE_64BIT,
1762 Features::EXTERNAL_TEXTURE,
1763 Features::SHADER_F64,
1764 Features::SHADER_I16,
1765 Features::SHADER_EARLY_DEPTH_TEST,
1766 Features::PASSTHROUGH_SHADERS,
1767 ];
1768
1769 if feature == Features::SUBGROUP {
1770 // Standard-track feature that does not have `wgpu-` prefix
1771 assert_eq!(name.parse(), Ok(feature));
1772 } else if feature & Features::all_native_mask() != Features::empty() {
1773 let stripped_name = name.strip_prefix("wgpu-").unwrap_or_else(|| {
1774 panic!("Native feature `{name}` should have `wgpu-` prefix")
1775 });
1776 let expected = if prefix_backcompat_features.contains(&feature) {
1777 Ok(feature)
1778 } else {
1779 Err(())
1780 };
1781 assert_eq!(stripped_name.parse(), expected);
1782 }
1783
1784 // Special backcompat case
1785 if feature == Features::PRIMITIVE_INDEX {
1786 assert_eq!("shader-primitive-index".parse(), Ok(feature));
1787 }
1788 }
1789 }
1790
1791 #[test]
1792 fn create_features_from_parts() {
1793 let features: Features = FeaturesWGPU::TEXTURE_ATOMIC.into();
1794 assert_eq!(features, Features::TEXTURE_ATOMIC);
1795
1796 let features: Features = FeaturesWebGPU::TIMESTAMP_QUERY.into();
1797 assert_eq!(features, Features::TIMESTAMP_QUERY);
1798
1799 let features: Features = Features::from(FeaturesWGPU::TEXTURE_ATOMIC)
1800 | Features::from(FeaturesWebGPU::TIMESTAMP_QUERY);
1801 assert_eq!(
1802 features,
1803 Features::TEXTURE_ATOMIC | Features::TIMESTAMP_QUERY
1804 );
1805 assert_eq!(
1806 features,
1807 Features::from_internal_flags(
1808 FeaturesWGPU::TEXTURE_ATOMIC,
1809 FeaturesWebGPU::TIMESTAMP_QUERY
1810 )
1811 );
1812 }
1813
1814 #[test]
1815 fn experimental_features_part_of_experimental_mask() {
1816 for (name, feature) in Features::all().iter_names() {
1817 let prefixed_with_experimental = name.starts_with("EXPERIMENTAL_");
1818 let in_experimental_mask = Features::all_experimental_mask().contains(feature);
1819 assert_eq!(in_experimental_mask, prefixed_with_experimental);
1820 }
1821 }
1822}