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