Skip to main content

cart_tmp_wgt/
lib.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5// The intra doc links to the wgpu crate in this crate actually succesfully link to the types in the wgpu crate, when built from the wgpu crate.
6// However when building from both the wgpu crate or this crate cargo doc will claim all the links cannot be resolved
7// despite the fact that it works fine when it needs to.
8// So we just disable those warnings.
9#![allow(intra_doc_link_resolution_failure)]
10
11#[cfg(feature = "serde")]
12use serde::{Deserialize, Serialize};
13
14/// Integral type used for buffer offsets.
15pub type BufferAddress = u64;
16/// Integral type used for buffer slice sizes.
17pub type BufferSize = std::num::NonZeroU64;
18
19/// Buffer-Texture copies must have [`bytes_per_row`] aligned to this number.
20///
21/// This doesn't apply to [`Queue::write_texture`].
22///
23/// [`bytes_per_row`]: TextureDataLayout::bytes_per_row
24pub const COPY_BYTES_PER_ROW_ALIGNMENT: u32 = 256;
25/// Bound uniform/storage buffer offsets must be aligned to this number.
26pub const BIND_BUFFER_ALIGNMENT: BufferAddress = 256;
27/// Buffer to buffer copy offsets and sizes must be aligned to this number.
28pub const COPY_BUFFER_ALIGNMENT: BufferAddress = 4;
29
30/// Backends supported by wgpu.
31#[repr(u8)]
32#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
33#[cfg_attr(feature = "trace", derive(Serialize))]
34#[cfg_attr(feature = "replay", derive(Deserialize))]
35pub enum Backend {
36    Empty = 0,
37    Vulkan = 1,
38    Metal = 2,
39    Dx12 = 3,
40    Dx11 = 4,
41    Gl = 5,
42    BrowserWebGpu = 6,
43}
44
45/// Power Preference when choosing a physical adapter.
46#[repr(C)]
47#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
48#[cfg_attr(feature = "trace", derive(Serialize))]
49#[cfg_attr(feature = "replay", derive(Deserialize))]
50pub enum PowerPreference {
51    /// Prefer low power when on battery, high performance when on mains.
52    Default = 0,
53    /// Adapter that uses the least possible power. This is often an integerated GPU.
54    LowPower = 1,
55    /// Adapter that has the highest performance. This is often a discrete GPU.
56    HighPerformance = 2,
57}
58
59impl Default for PowerPreference {
60    fn default() -> PowerPreference {
61        PowerPreference::Default
62    }
63}
64
65bitflags::bitflags! {
66    /// Represents the backends that wgpu will use.
67    #[repr(transparent)]
68    #[cfg_attr(feature = "trace", derive(Serialize))]
69    #[cfg_attr(feature = "replay", derive(Deserialize))]
70    pub struct BackendBit: u32 {
71        /// Supported on Windows, Linux/Android, and macOS/iOS via Vulkan Portability (with the Vulkan feature enabled)
72        const VULKAN = 1 << Backend::Vulkan as u32;
73        /// Currently unsupported
74        const GL = 1 << Backend::Gl as u32;
75        /// Supported on macOS/iOS
76        const METAL = 1 << Backend::Metal as u32;
77        /// Supported on Windows 10
78        const DX12 = 1 << Backend::Dx12 as u32;
79        /// Supported on Windows 7+
80        const DX11 = 1 << Backend::Dx11 as u32;
81        /// Supported when targeting the web through webassembly
82        const BROWSER_WEBGPU = 1 << Backend::BrowserWebGpu as u32;
83        /// All the apis that wgpu offers first tier of support for.
84        ///
85        /// Vulkan + Metal + DX12 + Browser WebGPU
86        const PRIMARY = Self::VULKAN.bits
87            | Self::METAL.bits
88            | Self::DX12.bits
89            | Self::BROWSER_WEBGPU.bits;
90        /// All the apis that wgpu offers second tier of support for. These may
91        /// be unsupported/still experimental.
92        ///
93        /// OpenGL + DX11
94        const SECONDARY = Self::GL.bits | Self::DX11.bits;
95    }
96}
97
98impl From<Backend> for BackendBit {
99    fn from(backend: Backend) -> Self {
100        BackendBit::from_bits(1 << backend as u32).unwrap()
101    }
102}
103
104/// This type is not to be constructed by any users of wgpu. If you construct this type, any semver
105/// guarantees made by wgpu are invalidated and a non-breaking change may break your code.
106///
107/// If you are here trying to construct it, the solution is to use partial construction with the
108/// default:
109///
110/// ```ignore
111/// let limits = Limits {
112///     max_bind_groups: 2,
113///     ..Limits::default()
114/// }
115/// ```
116#[doc(hidden)]
117#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Hash)]
118#[cfg_attr(feature = "trace", derive(Serialize))]
119#[cfg_attr(feature = "replay", derive(Deserialize))]
120pub struct NonExhaustive(());
121
122impl NonExhaustive {
123    pub unsafe fn new() -> Self {
124        Self(())
125    }
126}
127
128bitflags::bitflags! {
129    /// Features that are not guaranteed to be supported.
130    ///
131    /// These are either part of the webgpu standard, or are extension features supported by
132    /// wgpu when targeting native.
133    ///
134    /// If you want to use a feature, you need to first verify that the adapter supports
135    /// the feature. If the adapter does not support the feature, requesting a device with it enabled
136    /// will panic.
137    #[repr(transparent)]
138    #[derive(Default)]
139    #[cfg_attr(feature = "trace", derive(Serialize))]
140    #[cfg_attr(feature = "replay", derive(Deserialize))]
141    pub struct Features: u64 {
142        /// Webgpu only allows the MAP_READ and MAP_WRITE buffer usage to be matched with
143        /// COPY_DST and COPY_SRC respectively. This removes this requirement.
144        ///
145        /// This is only beneficial on systems that share memory between CPU and GPU. If enabled
146        /// on a system that doesn't, this can severely hinder performance. Only use if you understand
147        /// the consequences.
148        ///
149        /// Supported platforms:
150        /// - All
151        ///
152        /// This is a native only feature.
153        const MAPPABLE_PRIMARY_BUFFERS = 0x0000_0000_0001_0000;
154        /// Allows the user to create uniform arrays of sampled textures in shaders:
155        ///
156        /// eg. `uniform texture2D textures[10]`.
157        ///
158        /// This capability allows them to exist and to be indexed by compile time constant
159        /// values.
160        ///
161        /// Supported platforms:
162        /// - DX12
163        /// - Metal (with MSL 2.0+ on macOS 10.13+)
164        /// - Vulkan
165        ///
166        /// This is a native only feature.
167        const SAMPLED_TEXTURE_BINDING_ARRAY = 0x0000_0000_0002_0000;
168        /// Allows shaders to index sampled texture arrays with dynamically uniform values:
169        ///
170        /// eg. `texture_array[uniform_value]`
171        ///
172        /// This capability means the hardware will also support SAMPLED_TEXTURE_BINDING_ARRAY.
173        ///
174        /// Supported platforms:
175        /// - DX12
176        /// - Metal (with MSL 2.0+ on macOS 10.13+)
177        /// - Vulkan's shaderSampledImageArrayDynamicIndexing feature
178        ///
179        /// This is a native only feature.
180        const SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING = 0x0000_0000_0004_0000;
181        /// Allows shaders to index sampled texture arrays with dynamically non-uniform values:
182        ///
183        /// eg. `texture_array[vertex_data]`
184        ///
185        /// In order to use this capability, the corresponding GLSL extension must be enabled like so:
186        ///
187        /// `#extension GL_EXT_nonuniform_qualifier : require`
188        ///
189        /// HLSL does not need any extension.
190        ///
191        /// This capability means the hardware will also support SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING
192        /// and SAMPLED_TEXTURE_BINDING_ARRAY.
193        ///
194        /// Supported platforms:
195        /// - DX12
196        /// - Metal (with MSL 2.0+ on macOS 10.13+)
197        /// - Vulkan 1.2+ (or VK_EXT_descriptor_indexing)'s shaderSampledImageArrayNonUniformIndexing feature)
198        ///
199        /// This is a native only feature.
200        const SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING = 0x0000_0000_0008_0000;
201        /// Allows the user to create unsized uniform arrays of bindings:
202        ///
203        /// eg. `uniform texture2D textures[]`.
204        ///
205        /// If this capability is supported, SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING is very likely
206        /// to also be supported
207        ///
208        /// Supported platforms:
209        /// - DX12
210        /// - Vulkan 1.2+ (or VK_EXT_descriptor_indexing)'s runtimeDescriptorArray feature
211        ///
212        /// This is a native only feature.
213        const UNSIZED_BINDING_ARRAY = 0x0000_0000_0010_0000;
214        /// Allows the user to call [`RenderPass::multi_draw_indirect`] and [`RenderPass::multi_draw_indexed_indirect`].
215        ///
216        /// Allows multiple indirect calls to be dispatched from a single buffer.
217        ///
218        /// Supported platforms:
219        /// - DX12
220        /// - Metal
221        /// - Vulkan
222        ///
223        /// This is a native only feature.
224        const MULTI_DRAW_INDIRECT = 0x0000_0000_0020_0000;
225        /// Allows the user to call [`RenderPass::multi_draw_indirect_count`] and [`RenderPass::multi_draw_indexed_indirect_count`].
226        ///
227        /// This allows the use of a buffer containing the actual number of draw calls.
228        ///
229        /// Supported platforms:
230        /// - DX12
231        /// - Vulkan 1.2+ (or VK_KHR_draw_indirect_count)
232        ///
233        /// This is a native only feature.
234        const MULTI_DRAW_INDIRECT_COUNT = 0x0000_0000_0040_0000;
235        /// Features which are part of the upstream webgpu standard
236        const ALL_WEBGPU = 0x0000_0000_0000_FFFF;
237        /// Features that are only available when targeting native (not web)
238        const ALL_NATIVE = 0xFFFF_FFFF_FFFF_0000;
239    }
240}
241
242/// Represents the sets of limits an adapter/device supports.
243///
244/// Limits "better" than the default must be supported by the adapter and requested when requesting
245/// a device. If limits "better" than the adapter supports are requested, requesting a device will panic.
246/// Once a device is requested, you may only use resources up to the limits requested _even_ if the
247/// adapter supports "better" limits.
248///
249/// Requesting limits that are "better" than you need may cause performance to decrease because the
250/// implementation needs to support more than is needed. You should ideally only request exactly what
251/// you need.
252///
253/// See also: https://gpuweb.github.io/gpuweb/#dictdef-gpulimits
254#[repr(C)]
255#[derive(Clone, Debug, PartialEq, Eq, Hash)]
256#[cfg_attr(feature = "trace", derive(Serialize))]
257#[cfg_attr(feature = "replay", derive(Deserialize))]
258pub struct Limits {
259    /// Amount of bind groups that can be attached to a pipeline at the same time. Defaults to 4. Higher is "better".
260    pub max_bind_groups: u32,
261    /// This struct must be partially constructed from its default.
262    pub _non_exhaustive: NonExhaustive,
263}
264
265impl Default for Limits {
266    fn default() -> Self {
267        Limits {
268            max_bind_groups: 4,
269            _non_exhaustive: unsafe { NonExhaustive::new() },
270        }
271    }
272}
273
274/// Describes a [`Device`].
275#[repr(C)]
276#[derive(Clone, Debug, Default)]
277#[cfg_attr(feature = "trace", derive(Serialize))]
278#[cfg_attr(feature = "replay", derive(Deserialize))]
279pub struct DeviceDescriptor {
280    /// Features that the device should support. If any feature is not supported by
281    /// the adapter, creating a device will panic.
282    pub features: Features,
283    /// Limits that the device should support. If any limit is "better" than the limit exposed by
284    /// the adapter, creating a device will panic.
285    pub limits: Limits,
286    /// Switch shader validation on/off. This is a temporary field
287    /// that will be removed once our validation logic is complete.
288    pub shader_validation: bool,
289}
290
291bitflags::bitflags! {
292    /// Describes the shader stages that a binding will be visible from.
293    ///
294    /// These can be combined so something that is visible from both vertex and fragment shaders can be defined as:
295    ///
296    /// `ShaderStage::VERTEX | ShaderStage::FRAGMENT`
297    #[repr(transparent)]
298    #[cfg_attr(feature = "trace", derive(Serialize))]
299    #[cfg_attr(feature = "replay", derive(Deserialize))]
300    pub struct ShaderStage: u32 {
301        /// Binding is not visible from any shader stage
302        const NONE = 0;
303        /// Binding is visible from the vertex shader of a render pipeline
304        const VERTEX = 1;
305        /// Binding is visible from the fragment shader of a render pipeline
306        const FRAGMENT = 2;
307        /// Binding is visible from the compute shader of a compute pipeline
308        const COMPUTE = 4;
309    }
310}
311
312/// Dimensions of a particular texture view.
313#[repr(C)]
314#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
315#[cfg_attr(feature = "trace", derive(Serialize))]
316#[cfg_attr(feature = "replay", derive(Deserialize))]
317pub enum TextureViewDimension {
318    /// A one dimensional texture. `texture1D` in glsl shaders.
319    D1,
320    /// A two dimensional texture. `texture2D` in glsl shaders.
321    D2,
322    /// A two dimensional array texture. `texture2DArray` in glsl shaders.
323    D2Array,
324    /// A cubemap texture. `textureCube` in glsl shaders.
325    Cube,
326    /// A cubemap array texture. `textureCubeArray` in glsl shaders.
327    CubeArray,
328    /// A three dimensional texture. `texture3D` in glsl shaders.
329    D3,
330}
331
332/// Alpha blend factor.
333///
334/// Alpha blending is very complicated: see the OpenGL or Vulkan spec for more information.
335#[repr(C)]
336#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
337#[cfg_attr(feature = "trace", derive(Serialize))]
338#[cfg_attr(feature = "replay", derive(Deserialize))]
339pub enum BlendFactor {
340    Zero = 0,
341    One = 1,
342    SrcColor = 2,
343    OneMinusSrcColor = 3,
344    SrcAlpha = 4,
345    OneMinusSrcAlpha = 5,
346    DstColor = 6,
347    OneMinusDstColor = 7,
348    DstAlpha = 8,
349    OneMinusDstAlpha = 9,
350    SrcAlphaSaturated = 10,
351    BlendColor = 11,
352    OneMinusBlendColor = 12,
353}
354
355/// Alpha blend operation.
356///
357/// Alpha blending is very complicated: see the OpenGL or Vulkan spec for more information.
358#[repr(C)]
359#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
360#[cfg_attr(feature = "trace", derive(Serialize))]
361#[cfg_attr(feature = "replay", derive(Deserialize))]
362pub enum BlendOperation {
363    Add = 0,
364    Subtract = 1,
365    ReverseSubtract = 2,
366    Min = 3,
367    Max = 4,
368}
369
370impl Default for BlendOperation {
371    fn default() -> Self {
372        BlendOperation::Add
373    }
374}
375
376/// Describes the blend state of a pipeline.
377///
378/// Alpha blending is very complicated: see the OpenGL or Vulkan spec for more information.
379#[repr(C)]
380#[derive(Clone, Debug, PartialEq, Eq, Hash)]
381#[cfg_attr(feature = "trace", derive(Serialize))]
382#[cfg_attr(feature = "replay", derive(Deserialize))]
383pub struct BlendDescriptor {
384    pub src_factor: BlendFactor,
385    pub dst_factor: BlendFactor,
386    pub operation: BlendOperation,
387}
388
389impl BlendDescriptor {
390    pub const REPLACE: Self = BlendDescriptor {
391        src_factor: BlendFactor::One,
392        dst_factor: BlendFactor::Zero,
393        operation: BlendOperation::Add,
394    };
395
396    pub fn uses_color(&self) -> bool {
397        match (self.src_factor, self.dst_factor) {
398            (BlendFactor::BlendColor, _)
399            | (BlendFactor::OneMinusBlendColor, _)
400            | (_, BlendFactor::BlendColor)
401            | (_, BlendFactor::OneMinusBlendColor) => true,
402            (_, _) => false,
403        }
404    }
405}
406
407impl Default for BlendDescriptor {
408    fn default() -> Self {
409        BlendDescriptor::REPLACE
410    }
411}
412
413/// Describes the color state of a render pipeline.
414#[repr(C)]
415#[derive(Clone, Debug, PartialEq, Eq, Hash)]
416#[cfg_attr(feature = "trace", derive(Serialize))]
417#[cfg_attr(feature = "replay", derive(Deserialize))]
418pub struct ColorStateDescriptor {
419    /// The [`TextureFormat`] of the image that this pipeline will render to. Must match the the format
420    /// of the corresponding color attachment in [`CommandEncoder::begin_render_pass`].
421    pub format: TextureFormat,
422    /// The alpha blending that is used for this pipeline.
423    pub alpha_blend: BlendDescriptor,
424    /// The color blending that is used for this pipeline.
425    pub color_blend: BlendDescriptor,
426    /// Mask which enables/disables writes to different color/alpha channel.
427    pub write_mask: ColorWrite,
428}
429
430/// Primitive type the input mesh is composed of.
431#[repr(C)]
432#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
433#[cfg_attr(feature = "trace", derive(Serialize))]
434#[cfg_attr(feature = "replay", derive(Deserialize))]
435pub enum PrimitiveTopology {
436    /// Vertex data is a list of points. Each vertex is a new point.
437    PointList = 0,
438    /// Vertex data is a list of lines. Each pair of vertices composes a new line.
439    ///
440    /// Vertices `0 1 2 3` create two lines `0 1` and `2 3`
441    LineList = 1,
442    /// Vertex data is a strip of lines. Each set of two adjacent vertices form a line.
443    ///
444    /// Vertices `0 1 2 3` create three lines `0 1`, `1 2`, and `2 3`.
445    LineStrip = 2,
446    /// Vertex data is a list of triangles. Each set of 3 vertices composes a new triangle.
447    ///
448    /// Vertices `0 1 2 3 4 5` create two triangles `0 1 2` and `3 4 5`
449    TriangleList = 3,
450    /// Vertex data is a triangle strip. Each set of three adjacent vertices form a triangle.
451    ///
452    /// Vertices `0 1 2 3 4 5` creates four triangles `0 1 2`, `2 1 3`, `3 2 4`, and `4 3 5`
453    TriangleStrip = 4,
454}
455
456/// Winding order which classifies the "front" face.
457#[repr(C)]
458#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
459#[cfg_attr(feature = "trace", derive(Serialize))]
460#[cfg_attr(feature = "replay", derive(Deserialize))]
461pub enum FrontFace {
462    /// Triangles with vertices in counter clockwise order are considered the front face.
463    ///
464    /// This is the default with right handed coordinate spaces.
465    Ccw = 0,
466    /// Triangles with vertices in clockwise order are considered the front face.
467    ///
468    /// This is the default with left handed coordinate spaces.
469    Cw = 1,
470}
471
472impl Default for FrontFace {
473    fn default() -> Self {
474        FrontFace::Ccw
475    }
476}
477
478/// Type of faces to be culled.
479#[repr(C)]
480#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
481#[cfg_attr(feature = "trace", derive(Serialize))]
482#[cfg_attr(feature = "replay", derive(Deserialize))]
483pub enum CullMode {
484    /// No faces should be culled
485    None = 0,
486    /// Front faces should be culled
487    Front = 1,
488    /// Back faces should be culled
489    Back = 2,
490}
491
492impl Default for CullMode {
493    fn default() -> Self {
494        CullMode::None
495    }
496}
497
498/// Describes the state of the rasterizer in a render pipeline.
499#[repr(C)]
500#[derive(Clone, Debug, Default, PartialEq)]
501#[cfg_attr(feature = "trace", derive(Serialize))]
502#[cfg_attr(feature = "replay", derive(Deserialize))]
503pub struct RasterizationStateDescriptor {
504    pub front_face: FrontFace,
505    pub cull_mode: CullMode,
506    pub depth_bias: i32,
507    pub depth_bias_slope_scale: f32,
508    pub depth_bias_clamp: f32,
509}
510
511/// Underlying texture data format.
512///
513/// If there is a conversion in the format (such as srgb -> linear), The conversion listed is for
514/// loading from texture in a shader. When writing to the texture, the opposite conversion takes place.
515#[repr(C)]
516#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
517#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
518pub enum TextureFormat {
519    // Normal 8 bit formats
520    /// Red channel only. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader.
521    R8Unorm = 0,
522    /// Red channel only. 8 bit integer per channel. [-127, 127] converted to/from float [-1, 1] in shader.
523    R8Snorm = 1,
524    /// Red channel only. 8 bit integer per channel. Unsigned in shader.
525    R8Uint = 2,
526    /// Red channel only. 8 bit integer per channel. Signed in shader.
527    R8Sint = 3,
528
529    // Normal 16 bit formats
530    /// Red channel only. 16 bit integer per channel. Unsigned in shader.
531    R16Uint = 4,
532    /// Red channel only. 16 bit integer per channel. Signed in shader.
533    R16Sint = 5,
534    /// Red channel only. 16 bit float per channel. Float in shader.
535    R16Float = 6,
536    /// Red and green channels. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader.
537    Rg8Unorm = 7,
538    /// Red and green channels. 8 bit integer per channel. [-127, 127] converted to/from float [-1, 1] in shader.
539    Rg8Snorm = 8,
540    /// Red and green channels. 8 bit integer per channel. Unsigned in shader.
541    Rg8Uint = 9,
542    /// Red and green channel s. 8 bit integer per channel. Signed in shader.
543    Rg8Sint = 10,
544
545    // Normal 32 bit formats
546    /// Red channel only. 32 bit integer per channel. Unsigned in shader.
547    R32Uint = 11,
548    /// Red channel only. 32 bit integer per channel. Signed in shader.
549    R32Sint = 12,
550    /// Red channel only. 32 bit float per channel. Float in shader.
551    R32Float = 13,
552    /// Red and green channels. 16 bit integer per channel. Unsigned in shader.
553    Rg16Uint = 14,
554    /// Red and green channels. 16 bit integer per channel. Signed in shader.
555    Rg16Sint = 15,
556    /// Red and green channels. 16 bit float per channel. Float in shader.
557    Rg16Float = 16,
558    /// Red, green, blue, and alpha channels. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader.
559    Rgba8Unorm = 17,
560    /// Red, green, blue, and alpha channels. 8 bit integer per channel. Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader.
561    Rgba8UnormSrgb = 18,
562    /// Red, green, blue, and alpha channels. 8 bit integer per channel. [-127, 127] converted to/from float [-1, 1] in shader.
563    Rgba8Snorm = 19,
564    /// Red, green, blue, and alpha channels. 8 bit integer per channel. Unsigned in shader.
565    Rgba8Uint = 20,
566    /// Red, green, blue, and alpha channels. 8 bit integer per channel. Signed in shader.
567    Rgba8Sint = 21,
568    /// Blue, green, red, and alpha channels. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader.
569    Bgra8Unorm = 22,
570    /// Blue, green, red, and alpha channels. 8 bit integer per channel. Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader.
571    Bgra8UnormSrgb = 23,
572
573    // Packed 32 bit formats
574    /// Red, green, blue, and alpha channels. 10 bit integer for RGB channels, 2 bit integer for alpha channel. [0, 1023] ([0, 3] for alpha) converted to/from float [0, 1] in shader.
575    Rgb10a2Unorm = 24,
576    /// Red, green, and blue channels. 11 bit float with no sign bit for RG channels. 10 bit float with no sign bti for blue channel. Float in shader.
577    Rg11b10Float = 25,
578
579    // Normal 64 bit formats
580    /// Red and green channels. 32 bit integer per channel. Unsigned in shader.
581    Rg32Uint = 26,
582    /// Red and green channels. 32 bit integer per channel. Signed in shader.
583    Rg32Sint = 27,
584    /// Red and green channels. 32 bit float per channel. Float in shader.
585    Rg32Float = 28,
586    /// Red, green, blue, and alpha channels. 16 bit integer per channel. Unsigned in shader.
587    Rgba16Uint = 29,
588    /// Red, green, blue, and alpha channels. 16 bit integer per channel. Signed in shader.
589    Rgba16Sint = 30,
590    /// Red, green, blue, and alpha channels. 16 bit float per channel. Float in shader.
591    Rgba16Float = 31,
592
593    // Normal 128 bit formats
594    /// Red, green, blue, and alpha channels. 32 bit integer per channel. Unsigned in shader.
595    Rgba32Uint = 32,
596    /// Red, green, blue, and alpha channels. 32 bit integer per channel. Signed in shader.
597    Rgba32Sint = 33,
598    /// Red, green, blue, and alpha channels. 32 bit float per channel. Float in shader.
599    Rgba32Float = 34,
600
601    // Depth and stencil formats
602    /// Special depth format with 32 bit floating point depth.
603    Depth32Float = 35,
604    /// Special depth format with at least 24 bit integer depth.
605    Depth24Plus = 36,
606    /// Special depth/stencil format with at least 24 bit integer depth and 8 bits integer stencil.
607    Depth24PlusStencil8 = 37,
608}
609
610bitflags::bitflags! {
611    /// Color write mask. Disabled color channels will not be written to.
612    #[repr(transparent)]
613    #[cfg_attr(feature = "trace", derive(Serialize))]
614    #[cfg_attr(feature = "replay", derive(Deserialize))]
615    pub struct ColorWrite: u32 {
616        /// Enable red channel writes
617        const RED = 1;
618        /// Enable green channel writes
619        const GREEN = 2;
620        /// Enable blue channel writes
621        const BLUE = 4;
622        /// Enable alpha channel writes
623        const ALPHA = 8;
624        /// Enable red, green, and blue channel writes
625        const COLOR = 7;
626        /// Enable writes to all channels.
627        const ALL = 15;
628    }
629}
630
631impl Default for ColorWrite {
632    fn default() -> Self {
633        ColorWrite::ALL
634    }
635}
636
637/// Describes the depth/stencil state in a render pipeline.
638#[repr(C)]
639#[derive(Clone, Debug, PartialEq, Eq, Hash)]
640#[cfg_attr(feature = "trace", derive(Serialize))]
641#[cfg_attr(feature = "replay", derive(Deserialize))]
642pub struct DepthStencilStateDescriptor {
643    /// Format of the depth/stencil buffer, must be special depth format. Must match the the format
644    /// of the depth/stencil attachment in [`CommandEncoder::begin_render_pass`].
645    pub format: TextureFormat,
646    /// If disabled, depth will not be written to.
647    pub depth_write_enabled: bool,
648    /// Comparison function used to compare depth values in the depth test.
649    pub depth_compare: CompareFunction,
650    /// Stencil state used for front faces.
651    pub stencil_front: StencilStateFaceDescriptor,
652    /// Stencil state used for back faces.
653    pub stencil_back: StencilStateFaceDescriptor,
654    /// Stencil values are AND'd with this mask when reading and writing from the stencil buffer. Only low 8 bits are used.
655    pub stencil_read_mask: u32,
656    /// Stencil values are AND'd with this mask when writing to the stencil buffer. Only low 8 bits are used.
657    pub stencil_write_mask: u32,
658}
659
660impl DepthStencilStateDescriptor {
661    pub fn needs_stencil_reference(&self) -> bool {
662        !self.stencil_front.compare.is_trivial() || !self.stencil_back.compare.is_trivial()
663    }
664    pub fn is_read_only(&self) -> bool {
665        !self.depth_write_enabled && self.stencil_write_mask == 0
666    }
667}
668
669/// Format of indices used with pipeline.
670#[repr(C)]
671#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
672#[cfg_attr(feature = "trace", derive(Serialize))]
673#[cfg_attr(feature = "replay", derive(Deserialize))]
674pub enum IndexFormat {
675    /// Indices are 16 bit unsigned integers.
676    Uint16 = 0,
677    /// Indices are 32 bit unsigned integers.
678    Uint32 = 1,
679}
680
681impl Default for IndexFormat {
682    fn default() -> Self {
683        IndexFormat::Uint32
684    }
685}
686
687/// Operation to perform on the stencil value.
688#[repr(C)]
689#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
690#[cfg_attr(feature = "trace", derive(Serialize))]
691#[cfg_attr(feature = "replay", derive(Deserialize))]
692pub enum StencilOperation {
693    /// Keep stencil value unchanged.
694    Keep = 0,
695    /// Set stencil value to zero.
696    Zero = 1,
697    /// Replace stencil value with value provided in most recent call to [`RenderPass::set_stencil_reference`].
698    Replace = 2,
699    /// Bitwise inverts stencil value.
700    Invert = 3,
701    /// Increments stencil value by one, clamping on overflow.
702    IncrementClamp = 4,
703    /// Decrements stencil value by one, clamping on underflow.
704    DecrementClamp = 5,
705    /// Increments stencil value by one, wrapping on overflow.
706    IncrementWrap = 6,
707    /// Decrements stencil value by one, wrapping on underflow.
708    DecrementWrap = 7,
709}
710
711impl Default for StencilOperation {
712    fn default() -> Self {
713        StencilOperation::Keep
714    }
715}
716
717/// Describes stencil state in a render pipeline.
718///
719/// If you are not using stencil state, set this to [`StencilStateFaceDescriptor::IGNORE`].
720#[repr(C)]
721#[derive(Clone, Debug, PartialEq, Eq, Hash)]
722#[cfg_attr(feature = "trace", derive(Serialize))]
723#[cfg_attr(feature = "replay", derive(Deserialize))]
724pub struct StencilStateFaceDescriptor {
725    /// Comparison function that determines if the fail_op or pass_op is used on the stencil buffer.
726    pub compare: CompareFunction,
727    /// Operation that is preformed when stencil test fails.
728    pub fail_op: StencilOperation,
729    /// Operation that is performed when depth test fails but stencil test succeeds.
730    pub depth_fail_op: StencilOperation,
731    /// Operation that is performed when stencil test success.
732    pub pass_op: StencilOperation,
733}
734
735impl StencilStateFaceDescriptor {
736    pub const IGNORE: Self = StencilStateFaceDescriptor {
737        compare: CompareFunction::Always,
738        fail_op: StencilOperation::Keep,
739        depth_fail_op: StencilOperation::Keep,
740        pass_op: StencilOperation::Keep,
741    };
742}
743
744impl Default for StencilStateFaceDescriptor {
745    fn default() -> Self {
746        StencilStateFaceDescriptor::IGNORE
747    }
748}
749
750/// Comparison function used for depth and stencil operations.
751#[repr(C)]
752#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
753#[cfg_attr(feature = "trace", derive(Serialize))]
754#[cfg_attr(feature = "replay", derive(Deserialize))]
755pub enum CompareFunction {
756    /// Invalid value, do not use
757    Undefined = 0,
758    /// Function never passes
759    Never = 1,
760    /// Function passes if new value less than existing value
761    Less = 2,
762    /// Function passes if new value is equal to existing value
763    Equal = 3,
764    /// Function passes if new value is less than or equal to existing value
765    LessEqual = 4,
766    /// Function passes if new value is greater than existing value
767    Greater = 5,
768    /// Function passes if new value is not equal to existing value
769    NotEqual = 6,
770    /// Function passes if new value is greater than or equal to existing value
771    GreaterEqual = 7,
772    /// Function always passes
773    Always = 8,
774}
775
776impl CompareFunction {
777    pub fn is_trivial(self) -> bool {
778        match self {
779            CompareFunction::Never | CompareFunction::Always => true,
780            _ => false,
781        }
782    }
783}
784
785/// Integral type used for binding locations in shaders.
786pub type ShaderLocation = u32;
787
788/// Rate that determines when vertex data is advanced.
789#[repr(C)]
790#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
791#[cfg_attr(feature = "trace", derive(Serialize))]
792#[cfg_attr(feature = "replay", derive(Deserialize))]
793pub enum InputStepMode {
794    /// Input data is advanced every vertex. This is the standard value for vertex data.
795    Vertex = 0,
796    /// Input data is advanced every instance.
797    Instance = 1,
798}
799
800/// Vertex inputs (attributes) to shaders.
801///
802/// Arrays of these can be made with the [`vertex_attr_array`] macro. Vertex attributes are assumed to be tightly packed.
803#[repr(C)]
804#[derive(Clone, Debug, PartialEq, Eq, Hash)]
805#[cfg_attr(feature = "trace", derive(Serialize))]
806#[cfg_attr(feature = "replay", derive(Deserialize))]
807pub struct VertexAttributeDescriptor {
808    /// Byte offset of the start of the input
809    pub offset: BufferAddress,
810    /// Format of the input
811    pub format: VertexFormat,
812    /// Location for this input. Must match the location in the shader.
813    pub shader_location: ShaderLocation,
814}
815
816/// Describes how the vertex buffer is interpreted.
817#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
818pub struct VertexBufferDescriptor<'a> {
819    /// The stride, in bytes, between elements of this buffer.
820    pub stride: BufferAddress,
821    /// How often this vertex buffer is "stepped" forward.
822    pub step_mode: InputStepMode,
823    /// The list of attributes which comprise a single vertex.
824    pub attributes: &'a [VertexAttributeDescriptor],
825}
826
827/// Describes vertex input state for a render pipeline.
828#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
829pub struct VertexStateDescriptor<'a> {
830    /// The format of any index buffers used with this pipeline.
831    pub index_format: IndexFormat,
832    /// The format of any vertex buffers used with this pipeline.
833    pub vertex_buffers: &'a [VertexBufferDescriptor<'a>],
834}
835
836/// Vertex Format for a Vertex Attribute (input).
837#[repr(C)]
838#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
839#[cfg_attr(feature = "trace", derive(Serialize))]
840#[cfg_attr(feature = "replay", derive(Deserialize))]
841pub enum VertexFormat {
842    /// Two unsigned bytes (u8). `uvec2` in shaders.
843    Uchar2 = 0,
844    /// Four unsigned bytes (u8). `uvec4` in shaders.
845    Uchar4 = 1,
846    /// Two signed bytes (i8). `ivec2` in shaders.
847    Char2 = 2,
848    /// Four signed bytes (i8). `ivec4` in shaders.
849    Char4 = 3,
850    /// Two unsigned bytes (u8). [0, 255] converted to float [0, 1] `vec2` in shaders.
851    Uchar2Norm = 4,
852    /// Four unsigned bytes (u8). [0, 255] converted to float [0, 1] `vec4` in shaders.
853    Uchar4Norm = 5,
854    /// Two signed bytes (i8). [-127, 127] converted to float [-1, 1] `vec2` in shaders.
855    Char2Norm = 6,
856    /// Four signed bytes (i8). [-127, 127] converted to float [-1, 1] `vec4` in shaders.
857    Char4Norm = 7,
858    /// Two unsigned shorts (u16). `uvec2` in shaders.
859    Ushort2 = 8,
860    /// Four unsigned shorts (u16). `uvec4` in shaders.
861    Ushort4 = 9,
862    /// Two unsigned shorts (i16). `ivec2` in shaders.
863    Short2 = 10,
864    /// Four unsigned shorts (i16). `ivec4` in shaders.
865    Short4 = 11,
866    /// Two unsigned shorts (u16). [0, 65535] converted to float [0, 1] `vec2` in shaders.
867    Ushort2Norm = 12,
868    /// Four unsigned shorts (u16). [0, 65535] converted to float [0, 1] `vec4` in shaders.
869    Ushort4Norm = 13,
870    /// Two signed shorts (i16). [-32767, 32767] converted to float [-1, 1] `vec2` in shaders.
871    Short2Norm = 14,
872    /// Four signed shorts (i16). [-32767, 32767] converted to float [-1, 1] `vec4` in shaders.
873    Short4Norm = 15,
874    /// Two half-precision floats (no Rust equiv). `vec2` in shaders.
875    Half2 = 16,
876    /// Four half-precision floats (no Rust equiv). `vec4` in shaders.
877    Half4 = 17,
878    /// One single-precision float (f32). `float` in shaders.
879    Float = 18,
880    /// Two single-precision floats (f32). `vec2` in shaders.
881    Float2 = 19,
882    /// Three single-precision floats (f32). `vec3` in shaders.
883    Float3 = 20,
884    /// Four single-precision floats (f32). `vec4` in shaders.
885    Float4 = 21,
886    /// One unsigned int (u32). `uint` in shaders.
887    Uint = 22,
888    /// Two unsigned ints (u32). `uvec2` in shaders.
889    Uint2 = 23,
890    /// Three unsigned ints (u32). `uvec3` in shaders.
891    Uint3 = 24,
892    /// Four unsigned ints (u32). `uvec4` in shaders.
893    Uint4 = 25,
894    /// One signed int (i32). `int` in shaders.
895    Int = 26,
896    /// Two signed ints (i32). `ivec2` in shaders.
897    Int2 = 27,
898    /// Three signed ints (i32). `ivec3` in shaders.
899    Int3 = 28,
900    /// Four signed ints (i32). `ivec4` in shaders.
901    Int4 = 29,
902}
903
904bitflags::bitflags! {
905    /// Different ways that you can use a buffer.
906    ///
907    /// The usages determine what kind of memory the buffer is allocated from and what
908    /// actions the buffer can partake in.
909    #[repr(transparent)]
910    #[cfg_attr(feature = "trace", derive(Serialize))]
911    #[cfg_attr(feature = "replay", derive(Deserialize))]
912    pub struct BufferUsage: u32 {
913        /// Allow a buffer to be mapped for reading using [`Buffer::map_async`] + [`Buffer::get_mapped_range`].
914        /// This does not include creating a buffer with [`BufferDescriptor::mapped_at_creation`] set.
915        ///
916        /// If [`Features::MAPPABLE_PRIMARY_BUFFERS`] isn't enabled, the only other usage a buffer
917        /// may have is COPY_DST.
918        const MAP_READ = 1;
919        /// Allow a buffer to be mapped for writing using [`Buffer::map_async`] + [`Buffer::get_mapped_range_mut`].
920        /// This does not include creating a buffer with `mapped_at_creation` set.
921        ///
922        /// If [`Features::MAPPABLE_PRIMARY_BUFFERS`] feature isn't enabled, the only other usage a buffer
923        /// may have is COPY_SRC.
924        const MAP_WRITE = 2;
925        /// Allow a buffer to be the source buffer for a [`CommandEncoder::copy_buffer_to_buffer`] or [`CommandEncoder::copy_buffer_to_texture`]
926        /// operation.
927        const COPY_SRC = 4;
928        /// Allow a buffer to be the source buffer for a [`CommandEncoder::copy_buffer_to_buffer`], [`CommandEncoder::copy_buffer_to_texture`],
929        /// or [`Queue::write_buffer`] operation.
930        const COPY_DST = 8;
931        /// Allow a buffer to be the index buffer in a draw operation.
932        const INDEX = 16;
933        /// Allow a buffer to be the vertex buffer in a draw operation.
934        const VERTEX = 32;
935        /// Allow a buffer to be a [`BindingType::UniformBuffer`] inside a bind group.
936        const UNIFORM = 64;
937        /// Allow a buffer to be a [`BindingType::StorageBuffer`] inside a bind group.
938        const STORAGE = 128;
939        /// Allow a buffer to be the indirect buffer in an indirect draw call.
940        const INDIRECT = 256;
941    }
942}
943
944/// Describes a [`Buffer`].
945#[repr(C)]
946#[derive(Clone, Debug, PartialEq, Eq, Hash)]
947#[cfg_attr(feature = "trace", derive(Serialize))]
948#[cfg_attr(feature = "replay", derive(Deserialize))]
949pub struct BufferDescriptor<L> {
950    /// Debug label of a buffer. This will show up in graphics debuggers for easy identification.
951    pub label: L,
952    /// Size of a buffer.
953    pub size: BufferAddress,
954    /// Usages of a buffer. If the buffer is used in any way that isn't specified here, the operation
955    /// will panic.
956    pub usage: BufferUsage,
957    /// Allows a buffer to be mapped immediately after they are made. It does not have to be [`BufferUsage::MAP_READ`] or
958    /// [`BufferUsage::MAP_WRITE`], all buffers are allowed to be mapped at creation.
959    pub mapped_at_creation: bool,
960}
961
962impl<L> BufferDescriptor<L> {
963    pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> BufferDescriptor<K> {
964        BufferDescriptor {
965            label: fun(&self.label),
966            size: self.size,
967            usage: self.usage,
968            mapped_at_creation: self.mapped_at_creation,
969        }
970    }
971}
972
973/// Describes a [`CommandEncoder`].
974#[repr(C)]
975#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
976pub struct CommandEncoderDescriptor<L> {
977    /// Debug label for the command encoder. This will show up in graphics debuggers for easy identification.
978    pub label: L,
979}
980
981impl<L> CommandEncoderDescriptor<L> {
982    pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> CommandEncoderDescriptor<K> {
983        CommandEncoderDescriptor {
984            label: fun(&self.label),
985        }
986    }
987}
988
989/// Integral type used for dynamic bind group offsets.
990pub type DynamicOffset = u32;
991
992/// Behavior of the presentation engine based on frame rate.
993#[repr(C)]
994#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
995#[cfg_attr(feature = "trace", derive(Serialize))]
996#[cfg_attr(feature = "replay", derive(Deserialize))]
997pub enum PresentMode {
998    /// The presentation engine does **not** wait for a vertical blanking period and
999    /// the request is presented immediately. This is a low-latency presentation mode,
1000    /// but visible tearing may be observed. Will fallback to `Fifo` if unavailable on the
1001    /// selected  platform and backend. Not optimal for mobile.
1002    Immediate = 0,
1003    /// The presentation engine waits for the next vertical blanking period to update
1004    /// the current image, but frames may be submitted without delay. This is a low-latency
1005    /// presentation mode and visible tearing will **not** be observed. Will fallback to `Fifo`
1006    /// if unavailable on the selected platform and backend. Not optimal for mobile.
1007    Mailbox = 1,
1008    /// The presentation engine waits for the next vertical blanking period to update
1009    /// the current image. The framerate will be capped at the display refresh rate,
1010    /// corresponding to the `VSync`. Tearing cannot be observed. Optimal for mobile.
1011    Fifo = 2,
1012}
1013
1014bitflags::bitflags! {
1015    /// Different ways that you can use a texture.
1016    ///
1017    /// The usages determine what kind of memory the texture is allocated from and what
1018    /// actions the texture can partake in.
1019    #[repr(transparent)]
1020    #[cfg_attr(feature = "trace", derive(Serialize))]
1021    #[cfg_attr(feature = "replay", derive(Deserialize))]
1022    pub struct TextureUsage: u32 {
1023        /// Allows a texture to be the source in a [`CommandEncoder::copy_texture_to_buffer`] or
1024        /// [`CommandEncoder::copy_texture_to_texture`] operation.
1025        const COPY_SRC = 1;
1026        /// Allows a texture to be the destination in a  [`CommandEncoder::copy_texture_to_buffer`],
1027        /// [`CommandEncoder::copy_texture_to_texture`], or [`Queue::write_texture`] operation.
1028        const COPY_DST = 2;
1029        /// Allows a texture to be a [`BindingType::SampledTexture`] in a bind group.
1030        const SAMPLED = 4;
1031        /// Allows a texture to be a [`BindingType::StorageTexture`] in a bind group.
1032        const STORAGE = 8;
1033        /// Allows a texture to be a output attachment of a renderpass.
1034        const OUTPUT_ATTACHMENT = 16;
1035    }
1036}
1037
1038/// Describes a [`SwapChain`].
1039#[repr(C)]
1040#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1041#[cfg_attr(feature = "trace", derive(Serialize))]
1042#[cfg_attr(feature = "replay", derive(Deserialize))]
1043pub struct SwapChainDescriptor {
1044    /// The usage of the swap chain. The only supported usage is OUTPUT_ATTACHMENT
1045    pub usage: TextureUsage,
1046    /// The texture format of the swap chain. The only formats that are guaranteed are
1047    /// `Bgra8Unorm` and `Bgra8UnormSrgb`
1048    pub format: TextureFormat,
1049    /// Width of the swap chain. Must be the same size as the surface.
1050    pub width: u32,
1051    /// Height of the swap chain. Must be the same size as the surface.
1052    pub height: u32,
1053    /// Presentation mode of the swap chain. FIFO is the only guaranteed to be supported, though
1054    /// other formats will automatically fall back to FIFO.
1055    pub present_mode: PresentMode,
1056}
1057
1058/// Status of the recieved swapchain image.
1059#[repr(C)]
1060#[derive(Debug)]
1061pub enum SwapChainStatus {
1062    Good,
1063    Suboptimal,
1064    Timeout,
1065    Outdated,
1066    Lost,
1067    OutOfMemory,
1068}
1069
1070/// Operation to perform to the output attachment at the start of a renderpass.
1071#[repr(C)]
1072#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
1073#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1074pub enum LoadOp {
1075    /// Clear the output attachment with the clear color. Clearing is faster than loading.
1076    Clear = 0,
1077    /// Do not clear output attachment.
1078    Load = 1,
1079}
1080
1081/// Operation to perform to the output attachment at the end of a renderpass.
1082#[repr(C)]
1083#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
1084#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1085pub enum StoreOp {
1086    /// Clear the render target. If you don't care about the contents of the target, this can be faster.
1087    Clear = 0,
1088    /// Store the result of the renderpass.
1089    Store = 1,
1090}
1091
1092/// Describes an individual channel within a render pass, such as color, depth, or stencil.
1093#[repr(C)]
1094#[derive(Clone, Debug)]
1095#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1096pub struct PassChannel<V> {
1097    /// Operation to perform to the output attachment at the start of a renderpass. This must be clear if it
1098    /// is the first renderpass rendering to a swap chain image.
1099    pub load_op: LoadOp,
1100    /// Operation to perform to the output attachment at the end of a renderpass.
1101    pub store_op: StoreOp,
1102    /// If load_op is [`LoadOp::Clear`], the attachement will be cleared to this color.
1103    pub clear_value: V,
1104    /// If true, the relevant channel is not changed by a renderpass, and the corresponding attachment
1105    /// can be used inside the pass by other read-only usages.
1106    pub read_only: bool,
1107}
1108
1109/// Describes a color attachment to a [`RenderPass`].
1110#[repr(C)]
1111#[derive(Clone, Debug)]
1112#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1113pub struct RenderPassColorAttachmentDescriptorBase<T> {
1114    /// Texture attachment to render to. Must contain [`TextureUsage::OUTPUT_ATTACHMENT`].
1115    pub attachment: T,
1116    /// MSAA resolve target. Must contain [`TextureUsage::OUTPUT_ATTACHMENT`]. Must be `None` if
1117    /// attachment has 1 sample (does not have MSAA). This is not mandatory for rendering with multisampling,
1118    /// you can choose to resolve later or manually.
1119    pub resolve_target: Option<T>,
1120    /// Color channel.
1121    pub channel: PassChannel<Color>,
1122}
1123
1124/// Describes a depth/stencil attachment to a [`RenderPass`].
1125#[repr(C)]
1126#[derive(Clone, Debug)]
1127#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1128pub struct RenderPassDepthStencilAttachmentDescriptorBase<T> {
1129    /// Texture attachment to render to. Must contain [`TextureUsage::OUTPUT_ATTACHMENT`] and be a valid
1130    /// texture type for a depth/stencil attachment.
1131    pub attachment: T,
1132    /// Depth channel.
1133    pub depth: PassChannel<f32>,
1134    /// Stencil channel.
1135    pub stencil: PassChannel<u32>,
1136}
1137
1138/// RGBA double precision color.
1139///
1140/// This is not to be used as a generic color type, only for specific wgpu interfaces.
1141#[repr(C)]
1142#[derive(Clone, Copy, Debug, Default, PartialEq)]
1143#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1144pub struct Color {
1145    pub r: f64,
1146    pub g: f64,
1147    pub b: f64,
1148    pub a: f64,
1149}
1150
1151impl Color {
1152    pub const TRANSPARENT: Self = Color {
1153        r: 0.0,
1154        g: 0.0,
1155        b: 0.0,
1156        a: 0.0,
1157    };
1158    pub const BLACK: Self = Color {
1159        r: 0.0,
1160        g: 0.0,
1161        b: 0.0,
1162        a: 1.0,
1163    };
1164    pub const WHITE: Self = Color {
1165        r: 1.0,
1166        g: 1.0,
1167        b: 1.0,
1168        a: 1.0,
1169    };
1170    pub const RED: Self = Color {
1171        r: 1.0,
1172        g: 0.0,
1173        b: 0.0,
1174        a: 1.0,
1175    };
1176    pub const GREEN: Self = Color {
1177        r: 0.0,
1178        g: 1.0,
1179        b: 0.0,
1180        a: 1.0,
1181    };
1182    pub const BLUE: Self = Color {
1183        r: 0.0,
1184        g: 0.0,
1185        b: 1.0,
1186        a: 1.0,
1187    };
1188}
1189
1190/// Dimensionality of a texture.
1191#[repr(C)]
1192#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
1193#[cfg_attr(feature = "trace", derive(Serialize))]
1194#[cfg_attr(feature = "replay", derive(Deserialize))]
1195pub enum TextureDimension {
1196    /// 1D texture
1197    D1,
1198    /// 2D texture
1199    D2,
1200    /// 3D texture
1201    D3,
1202}
1203
1204/// Origin of a copy to/from a texture.
1205#[repr(C)]
1206#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1207#[cfg_attr(feature = "trace", derive(Serialize))]
1208#[cfg_attr(feature = "replay", derive(Deserialize))]
1209pub struct Origin3d {
1210    pub x: u32,
1211    pub y: u32,
1212    pub z: u32,
1213}
1214
1215impl Origin3d {
1216    pub const ZERO: Self = Origin3d { x: 0, y: 0, z: 0 };
1217}
1218
1219impl Default for Origin3d {
1220    fn default() -> Self {
1221        Origin3d::ZERO
1222    }
1223}
1224
1225/// Extent of a texture related operation.
1226#[repr(C)]
1227#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1228#[cfg_attr(feature = "trace", derive(Serialize))]
1229#[cfg_attr(feature = "replay", derive(Deserialize))]
1230pub struct Extent3d {
1231    pub width: u32,
1232    pub height: u32,
1233    pub depth: u32,
1234}
1235
1236/// Describes a [`Texture`].
1237#[repr(C)]
1238#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1239#[cfg_attr(feature = "trace", derive(Serialize))]
1240#[cfg_attr(feature = "replay", derive(Deserialize))]
1241pub struct TextureDescriptor<L> {
1242    /// Debug label of the texture. This will show up in graphics debuggers for easy identification.
1243    pub label: L,
1244    /// Size of the texture. For a regular 1D/2D texture, the unused sizes will be 1. For 2DArray textures, Z is the
1245    /// number of 2D textures in that array.
1246    pub size: Extent3d,
1247    /// Mip count of texture. For a texture with no extra mips, this must be 1.
1248    pub mip_level_count: u32,
1249    /// Sample count of texture. If this is not 1, texture must have [`BindingType::SampledTexture::multisampled`] set to true.
1250    pub sample_count: u32,
1251    /// Dimensions of the texture.
1252    pub dimension: TextureDimension,
1253    /// Format of the texture.
1254    pub format: TextureFormat,
1255    /// Allowed usages of the texture. If used in other ways, the operation will panic.
1256    pub usage: TextureUsage,
1257}
1258
1259impl<L> TextureDescriptor<L> {
1260    pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> TextureDescriptor<K> {
1261        TextureDescriptor {
1262            label: fun(&self.label),
1263            size: self.size,
1264            mip_level_count: self.mip_level_count,
1265            sample_count: self.sample_count,
1266            dimension: self.dimension,
1267            format: self.format,
1268            usage: self.usage,
1269        }
1270    }
1271}
1272
1273/// Kind of data the texture holds.
1274#[repr(C)]
1275#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
1276#[cfg_attr(feature = "trace", derive(Serialize))]
1277#[cfg_attr(feature = "replay", derive(Deserialize))]
1278pub enum TextureAspect {
1279    /// Depth, Stencil, and Color.
1280    All,
1281    /// Stencil.
1282    StencilOnly,
1283    /// Depth.
1284    DepthOnly,
1285}
1286
1287impl Default for TextureAspect {
1288    fn default() -> Self {
1289        TextureAspect::All
1290    }
1291}
1292
1293/// Describes a [`TextureView`].
1294#[repr(C)]
1295#[derive(Clone, Debug, PartialEq)]
1296#[cfg_attr(feature = "trace", derive(Serialize))]
1297#[cfg_attr(feature = "replay", derive(Deserialize))]
1298pub struct TextureViewDescriptor<L> {
1299    /// Debug label of the texture view. This will show up in graphics debuggers for easy identification.
1300    pub label: L,
1301    /// Format of the texture view. At this time, it must be the same as the underlying format of the texture.
1302    pub format: TextureFormat,
1303    /// The dimension of the texture view. For 1D textures, this must be `1D`. For 2D textures it must be one of
1304    /// `D2`, `D2Array`, `Cube`, and `CubeArray`. For 3D textures it must be `3D`
1305    pub dimension: TextureViewDimension,
1306    /// Aspect of the texture. Color textures must be [`TextureAspect::All`].
1307    pub aspect: TextureAspect,
1308    /// Base mip level.
1309    pub base_mip_level: u32,
1310    /// Mip level count. Must be at least one. base_mip_level + level_count must be less or equal to underlying texture mip count.
1311    pub level_count: u32,
1312    /// Base array layer.
1313    pub base_array_layer: u32,
1314    /// Layer count. Must be at least one. base_array_layer + array_layer_count must be less or equal to the underlying array count.
1315    pub array_layer_count: u32,
1316}
1317
1318impl<L> TextureViewDescriptor<L> {
1319    pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> TextureViewDescriptor<K> {
1320        TextureViewDescriptor {
1321            label: fun(&self.label),
1322            format: self.format,
1323            dimension: self.dimension,
1324            aspect: self.aspect,
1325            base_mip_level: self.base_mip_level,
1326            level_count: self.level_count,
1327            base_array_layer: self.base_array_layer,
1328            array_layer_count: self.array_layer_count,
1329        }
1330    }
1331}
1332
1333/// How edges should be handled in texture addressing.
1334#[repr(C)]
1335#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
1336#[cfg_attr(feature = "trace", derive(Serialize))]
1337#[cfg_attr(feature = "replay", derive(Deserialize))]
1338pub enum AddressMode {
1339    /// Clamp the value to the edge of the texture
1340    ///
1341    /// -0.25 -> 0.0
1342    /// 1.25  -> 1.0
1343    ClampToEdge = 0,
1344    /// Repeat the texture in a tiling fashion
1345    ///
1346    /// -0.25 -> 0.75
1347    /// 1.25 -> 0.25
1348    Repeat = 1,
1349    /// Repeat the texture, mirroring it every repeat
1350    ///
1351    /// -0.25 -> 0.25
1352    /// 1.25 -> 0.75
1353    MirrorRepeat = 2,
1354}
1355
1356impl Default for AddressMode {
1357    fn default() -> Self {
1358        AddressMode::ClampToEdge
1359    }
1360}
1361
1362/// Texel mixing mode when sampling between texels.
1363#[repr(C)]
1364#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
1365#[cfg_attr(feature = "trace", derive(Serialize))]
1366#[cfg_attr(feature = "replay", derive(Deserialize))]
1367pub enum FilterMode {
1368    /// Nearest neighbor sampling.
1369    ///
1370    /// This creates a pixelated effect when used as a mag filter
1371    Nearest = 0,
1372    /// Linear Interpolation
1373    ///
1374    /// This makes textures smooth but blurry when used as a mag filter.
1375    Linear = 1,
1376}
1377
1378impl Default for FilterMode {
1379    fn default() -> Self {
1380        FilterMode::Nearest
1381    }
1382}
1383
1384/// Describes a [`Sampler`]
1385#[derive(Clone, Debug, PartialEq)]
1386#[cfg_attr(feature = "trace", derive(Serialize))]
1387#[cfg_attr(feature = "replay", derive(Deserialize))]
1388pub struct SamplerDescriptor<L> {
1389    /// Debug label of the sampler. This will show up in graphics debuggers for easy identification.
1390    pub label: L,
1391    /// How to deal with out of bounds accesses in the u (i.e. x) direction
1392    pub address_mode_u: AddressMode,
1393    /// How to deal with out of bounds accesses in the v (i.e. y) direction
1394    pub address_mode_v: AddressMode,
1395    /// How to deal with out of bounds accesses in the w (i.e. z) direction
1396    pub address_mode_w: AddressMode,
1397    /// How to filter the texture when it needs to be magnified (made larger)
1398    pub mag_filter: FilterMode,
1399    /// How to filter the texture when it needs to be minified (made smaller)
1400    pub min_filter: FilterMode,
1401    /// How to filter between mip map levels
1402    pub mipmap_filter: FilterMode,
1403    /// Minimum level of detail (i.e. mip level) to use
1404    pub lod_min_clamp: f32,
1405    /// Maximum level of detail (i.e. mip level) to use
1406    pub lod_max_clamp: f32,
1407    /// If this is enabled, this is a comparison sampler using the given comparison function.
1408    pub compare: Option<CompareFunction>,
1409    /// Valid values: 1, 2, 4, 8, and 16.
1410    pub anisotropy_clamp: Option<u8>,
1411    /// This struct must be partially constructed from its default
1412    pub _non_exhaustive: NonExhaustive,
1413}
1414
1415impl<L: Default> Default for SamplerDescriptor<L> {
1416    fn default() -> Self {
1417        Self {
1418            label: Default::default(),
1419            address_mode_u: Default::default(),
1420            address_mode_v: Default::default(),
1421            address_mode_w: Default::default(),
1422            mag_filter: Default::default(),
1423            min_filter: Default::default(),
1424            mipmap_filter: Default::default(),
1425            lod_min_clamp: 0.0,
1426            lod_max_clamp: std::f32::MAX,
1427            compare: Default::default(),
1428            anisotropy_clamp: Default::default(),
1429            _non_exhaustive: Default::default(),
1430        }
1431    }
1432}
1433
1434impl<L> SamplerDescriptor<L> {
1435    pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> SamplerDescriptor<K> {
1436        SamplerDescriptor {
1437            label: fun(&self.label),
1438            address_mode_u: self.address_mode_u,
1439            address_mode_v: self.address_mode_v,
1440            address_mode_w: self.address_mode_w,
1441            mag_filter: self.mag_filter,
1442            min_filter: self.min_filter,
1443            mipmap_filter: self.mipmap_filter,
1444            lod_min_clamp: self.lod_min_clamp,
1445            lod_max_clamp: self.lod_max_clamp,
1446            compare: self.compare,
1447            anisotropy_clamp: self.anisotropy_clamp,
1448            _non_exhaustive: self._non_exhaustive,
1449        }
1450    }
1451}
1452
1453/// Describes a [`CommandBuffer`].
1454#[repr(C)]
1455#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
1456#[cfg_attr(feature = "trace", derive(Serialize))]
1457#[cfg_attr(feature = "replay", derive(Deserialize))]
1458pub struct CommandBufferDescriptor {
1459    /// Set this member to zero
1460    pub todo: u32,
1461}
1462
1463/// Describes a [`RenderBundleEncoder`].
1464#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
1465pub struct RenderBundleEncoderDescriptor<'a> {
1466    /// Debug label of the render bundle encoder. This will show up in graphics debuggers for easy identification.
1467    pub label: Option<&'a str>,
1468    /// The formats of the color attachments that this render bundle is capable to rendering to. This
1469    /// must match the formats of the color attachments in the renderpass this render bundle is executed in.
1470    pub color_formats: &'a [TextureFormat],
1471    /// The formats of the depth attachment that this render bundle is capable to rendering to. This
1472    /// must match the formats of the depth attachments in the renderpass this render bundle is executed in.
1473    pub depth_stencil_format: Option<TextureFormat>,
1474    /// Sample count this render bundle is capable of rendering to. This must match the pipelines and
1475    /// the renderpasses it is used in.
1476    pub sample_count: u32,
1477}
1478
1479/// Describes a [`RenderBundle`].
1480#[repr(C)]
1481#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
1482#[cfg_attr(feature = "trace", derive(Serialize))]
1483#[cfg_attr(feature = "replay", derive(Deserialize))]
1484pub struct RenderBundleDescriptor<L> {
1485    /// Debug label of the render bundle encoder. This will show up in graphics debuggers for easy identification.
1486    pub label: L,
1487}
1488
1489impl<L> RenderBundleDescriptor<L> {
1490    pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> RenderBundleDescriptor<K> {
1491        RenderBundleDescriptor {
1492            label: fun(&self.label),
1493        }
1494    }
1495}
1496
1497/// Type of data shaders will read from a texture.
1498///
1499/// Only relevant for [`BindingType::SampledTexture`] bindings. See [`TextureFormat`] for more information.
1500#[repr(C)]
1501#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
1502#[cfg_attr(feature = "trace", derive(Serialize))]
1503#[cfg_attr(feature = "replay", derive(Deserialize))]
1504pub enum TextureComponentType {
1505    /// They see it as a floating point number `texture1D`, `texture2D` etc
1506    Float,
1507    /// They see it as a signed integer `itexture1D`, `itexture2D` etc
1508    Sint,
1509    /// They see it as a unsigned integer `utexture1D`, `utexture2D` etc
1510    Uint,
1511}
1512
1513impl From<TextureFormat> for TextureComponentType {
1514    fn from(format: TextureFormat) -> Self {
1515        match format {
1516            TextureFormat::R8Uint
1517            | TextureFormat::R16Uint
1518            | TextureFormat::Rg8Uint
1519            | TextureFormat::R32Uint
1520            | TextureFormat::Rg16Uint
1521            | TextureFormat::Rgba8Uint
1522            | TextureFormat::Rg32Uint
1523            | TextureFormat::Rgba16Uint
1524            | TextureFormat::Rgba32Uint => Self::Uint,
1525
1526            TextureFormat::R8Sint
1527            | TextureFormat::R16Sint
1528            | TextureFormat::Rg8Sint
1529            | TextureFormat::R32Sint
1530            | TextureFormat::Rg16Sint
1531            | TextureFormat::Rgba8Sint
1532            | TextureFormat::Rg32Sint
1533            | TextureFormat::Rgba16Sint
1534            | TextureFormat::Rgba32Sint => Self::Sint,
1535
1536            TextureFormat::R8Unorm
1537            | TextureFormat::R8Snorm
1538            | TextureFormat::R16Float
1539            | TextureFormat::R32Float
1540            | TextureFormat::Rg8Unorm
1541            | TextureFormat::Rg8Snorm
1542            | TextureFormat::Rg16Float
1543            | TextureFormat::Rg11b10Float
1544            | TextureFormat::Rg32Float
1545            | TextureFormat::Rgba8Snorm
1546            | TextureFormat::Rgba16Float
1547            | TextureFormat::Rgba32Float
1548            | TextureFormat::Rgba8Unorm
1549            | TextureFormat::Rgba8UnormSrgb
1550            | TextureFormat::Bgra8Unorm
1551            | TextureFormat::Bgra8UnormSrgb
1552            | TextureFormat::Rgb10a2Unorm
1553            | TextureFormat::Depth32Float
1554            | TextureFormat::Depth24Plus
1555            | TextureFormat::Depth24PlusStencil8 => Self::Float,
1556        }
1557    }
1558}
1559
1560/// Layout of a texture in a buffer's memory.
1561#[repr(C)]
1562#[derive(Clone, Debug)]
1563#[cfg_attr(feature = "trace", derive(serde::Serialize))]
1564#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
1565pub struct TextureDataLayout {
1566    /// Offset into the buffer that is the start of the texture. Must be a multiple of texture block size.
1567    /// For non-compressed textures, this is 1.
1568    pub offset: BufferAddress,
1569    /// Bytes per "row" of the image. This represents one row of pixels in the x direction. Compressed
1570    /// textures include multiple rows of pixels in each "row". May be 0 for 1D texture copies.
1571    ///
1572    /// Must be a multiple of 256 for [`CommandEncoder::copy_buffer_to_texture`] and [`CommandEncoder::copy_texture_to_buffer`].
1573    /// [`Queue::write_texture`] does not have this requirement.
1574    ///
1575    /// Must be a multiple of the texture block size. For non-compressed textures, this is 1.
1576    pub bytes_per_row: u32,
1577    /// Rows that make up a single "image". Each "image" is one layer in the z direction of a 3D image. May be larger
1578    /// than `copy_size.y`.
1579    ///
1580    /// May be 0 for 2D texture copies.
1581    pub rows_per_image: u32,
1582}
1583
1584/// Specific type of a binding.
1585///
1586/// WebGPU spec: https://gpuweb.github.io/gpuweb/#dictdef-gpubindgrouplayoutentry
1587#[non_exhaustive]
1588#[derive(Clone, Debug, Eq, PartialEq)]
1589#[cfg_attr(feature = "trace", derive(Serialize))]
1590#[cfg_attr(feature = "replay", derive(Deserialize))]
1591pub enum BindingType {
1592    /// A buffer for uniform values.
1593    ///
1594    /// Example GLSL syntax:
1595    /// ```cpp,ignore
1596    /// layout(std140, binding = 0)
1597    /// uniform Globals {
1598    ///     vec2 aUniform;
1599    ///     vec2 anotherUniform;
1600    /// };
1601    /// ```
1602    UniformBuffer {
1603        /// Indicates that the binding has a dynamic offset.
1604        /// One offset must be passed to [`RenderPass::set_bind_group`] for each dynamic binding in increasing order of binding number.
1605        dynamic: bool,
1606        /// Minimum size of the corresponding `BufferBinding` required to match this entry.
1607        /// When pipeline is created, the size has to cover at least the corresponding structure in the shader
1608        /// plus one element of the unbound array, which can only be last in the structure.
1609        /// If `None`, the check is performed at draw call time instead of pipeline and bind group creation.
1610        min_binding_size: Option<BufferSize>,
1611    },
1612    /// A storage buffer.
1613    ///
1614    /// Example GLSL syntax:
1615    /// ```cpp,ignore
1616    /// layout (set=0, binding=0) buffer myStorageBuffer {
1617    ///     vec4 myElement[];
1618    /// };
1619    /// ```
1620    StorageBuffer {
1621        /// Indicates that the binding has a dynamic offset.
1622        /// One offset must be passed to [`RenderPass::set_bind_group`] for each dynamic binding in increasing order of binding number.
1623        dynamic: bool,
1624        /// Minimum size of the corresponding `BufferBinding` required to match this entry.
1625        /// When pipeline is created, the size has to cover at least the corresponding structure in the shader
1626        /// plus one element of the unbound array, which can only be last in the structure.
1627        /// If `None`, the check is performed at draw call time instead of pipeline and bind group creation.
1628        min_binding_size: Option<BufferSize>,
1629        /// The buffer can only be read in the shader and it must be annotated with `readonly`.
1630        ///
1631        /// Example GLSL syntax:
1632        /// ```cpp,ignore
1633        /// layout (set=0, binding=0) readonly buffer myStorageBuffer {
1634        ///     vec4 myElement[];
1635        /// };
1636        /// ```
1637        readonly: bool,
1638    },
1639    /// A sampler that can be used to sample a texture.
1640    ///
1641    /// Example GLSL syntax:
1642    /// ```cpp,ignore
1643    /// layout(binding = 0)
1644    /// uniform sampler s;
1645    /// ```
1646    Sampler {
1647        /// Use as a comparison sampler instead of a normal sampler.
1648        /// For more info take a look at the analogous functionality in OpenGL: https://www.khronos.org/opengl/wiki/Sampler_Object#Comparison_mode.
1649        comparison: bool,
1650    },
1651    /// A texture.
1652    ///
1653    /// Example GLSL syntax:
1654    /// ```cpp,ignore
1655    /// layout(binding = 0)
1656    /// uniform texture2D t;
1657    /// ```
1658    SampledTexture {
1659        /// Dimension of the texture view that is going to be sampled.
1660        dimension: TextureViewDimension,
1661        /// Component type of the texture.
1662        /// This must be compatible with the format of the texture.
1663        component_type: TextureComponentType,
1664        /// True if the texture has a sample count greater than 1. If this is true,
1665        /// the texture must be read from shaders with `texture1DMS`, `texture2DMS`, or `texture3DMS`,
1666        /// depending on `dimension`.
1667        multisampled: bool,
1668    },
1669    /// A storage texture.
1670    ///
1671    /// Example GLSL syntax:
1672    /// ```cpp,ignore
1673    /// layout(set=0, binding=0, r32f) uniform image2D myStorageImage;
1674    /// ```
1675    /// Note that the texture format must be specified in the shader as well.
1676    /// A list of valid formats can be found in the specification here: https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.html#layout-qualifiers
1677    StorageTexture {
1678        /// Dimension of the texture view that is going to be sampled.
1679        dimension: TextureViewDimension,
1680        /// Format of the texture.
1681        format: TextureFormat,
1682        /// The texture can only be read in the shader and it must be annotated with `readonly`.
1683        ///
1684        /// Example GLSL syntax:
1685        /// ```cpp,ignore
1686        /// layout(set=0, binding=0, r32f) readonly uniform image2D myStorageImage;
1687        /// ```
1688        readonly: bool,
1689    },
1690}
1691
1692/// Describes a single binding inside a bind group.
1693#[derive(Clone, Debug, PartialEq, Eq)]
1694#[cfg_attr(feature = "trace", derive(Serialize))]
1695#[cfg_attr(feature = "replay", derive(Deserialize))]
1696pub struct BindGroupLayoutEntry {
1697    /// Binding index. Must match shader index and be unique inside a BindGroupLayout. A binding
1698    /// of index 1, would be described as `layout(set = 0, binding = 1) uniform` in shaders.
1699    pub binding: u32,
1700    /// Which shader stages can see this binding.
1701    pub visibility: ShaderStage,
1702    /// The type of the binding
1703    pub ty: BindingType,
1704    /// If this value is Some, indicates this entry is an array. Array size must be 1 or greater.
1705    ///
1706    /// If this value is Some and `ty` is `BindingType::SampledTexture`, [`Capabilities::SAMPLED_TEXTURE_BINDING_ARRAY`] must be supported.
1707    ///
1708    /// If this value is Some and `ty` is any other variant, bind group creation will fail.
1709    pub count: Option<u32>,
1710    /// This struct should be partially initalized using the default method, but binding, visibility,
1711    /// and ty should be set.
1712    pub _non_exhaustive: NonExhaustive,
1713}
1714
1715impl BindGroupLayoutEntry {
1716    pub fn new(binding: u32, visibility: ShaderStage, ty: BindingType) -> Self {
1717        Self {
1718            binding,
1719            visibility,
1720            ty,
1721            count: None,
1722            _non_exhaustive: unsafe { NonExhaustive::new() },
1723        }
1724    }
1725
1726    pub fn has_dynamic_offset(&self) -> bool {
1727        match self.ty {
1728            BindingType::UniformBuffer { dynamic, .. }
1729            | BindingType::StorageBuffer { dynamic, .. } => dynamic,
1730            _ => false,
1731        }
1732    }
1733}
1734
1735/// Describes a [`BindGroupLayout`].
1736#[derive(Clone, Debug)]
1737pub struct BindGroupLayoutDescriptor<'a> {
1738    /// Debug label of the bind group layout. This will show up in graphics debuggers for easy identification.
1739    pub label: Option<&'a str>,
1740
1741    /// Array of bindings in this BindGroupLayout
1742    pub bindings: &'a [BindGroupLayoutEntry],
1743}