Debian Codegraph @

third_party/rust/wgpu-types/src/features.rs

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