wgpu/api/
mod.rs

1//! Types and functions which define our public api and their
2//! helper functionality.
3//!
4//! # Conventions
5//!
6//! Each major type gets its own module. The module is laid out as follows:
7//!
8//! - The type itself
9//! - `impl` block for the type
10//! - `Drop` implementation for the type (if needed)
11//! - Descriptor types and their subtypes.
12//! - Any non-public helper types or functions.
13//!
14//! # Imports
15//!
16//! Because our public api is "flat" (i.e. all types are directly under the `wgpu` module),
17//! we use a single `crate::*` import at the top of each module to bring in all the types in
18//! the public api. This is done to:
19//! - Avoid having to write out a long list of imports for each module.
20//! - Allow docs to be written naturally, without needing to worry about needing dedicated doc imports.
21//! - Treat wgpu-types types and wgpu-core types as a single set.
22//!
23
24mod adapter;
25mod bind_group;
26mod bind_group_layout;
27mod buffer;
28mod command_buffer;
29mod command_encoder;
30// Not a root type, but common descriptor types for pipelines.
31mod common_pipeline;
32mod compute_pass;
33mod compute_pipeline;
34mod device;
35mod instance;
36mod pipeline_cache;
37mod pipeline_layout;
38mod query_set;
39mod queue;
40mod render_bundle;
41mod render_bundle_encoder;
42mod render_pass;
43mod render_pipeline;
44mod sampler;
45mod shader_module;
46mod surface;
47mod surface_texture;
48mod texture;
49mod texture_view;
50
51pub use adapter::*;
52pub use bind_group::*;
53pub use bind_group_layout::*;
54pub use buffer::*;
55pub use command_buffer::*;
56pub use command_encoder::*;
57pub use common_pipeline::*;
58pub use compute_pass::*;
59pub use compute_pipeline::*;
60pub use device::*;
61pub use instance::*;
62pub use pipeline_cache::*;
63pub use pipeline_layout::*;
64pub use query_set::*;
65pub use queue::*;
66pub use render_bundle::*;
67pub use render_bundle_encoder::*;
68pub use render_pass::*;
69pub use render_pipeline::*;
70pub use sampler::*;
71pub use shader_module::*;
72pub use surface::*;
73pub use surface_texture::*;
74pub use texture::*;
75pub use texture_view::*;
76
77/// Object debugging label.
78pub type Label<'a> = Option<&'a str>;
79
80macro_rules! impl_partialeq_eq_hash {
81    ($ty:ty) => {
82        impl PartialEq for $ty {
83            fn eq(&self, other: &Self) -> bool {
84                std::ptr::addr_eq(self.data.as_ref(), other.data.as_ref())
85            }
86        }
87        impl Eq for $ty {}
88
89        impl std::hash::Hash for $ty {
90            fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
91                let ptr = self.data.as_ref() as *const Data as *const ();
92                ptr.hash(state);
93            }
94        }
95
96        impl PartialOrd for $ty {
97            fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
98                Some(self.cmp(other))
99            }
100        }
101        impl Ord for $ty {
102            fn cmp(&self, other: &Self) -> std::cmp::Ordering {
103                let a = self.data.as_ref() as *const Data as *const ();
104                let b = other.data.as_ref() as *const Data as *const ();
105                a.cmp(&b)
106            }
107        }
108    };
109}
110pub(crate) use impl_partialeq_eq_hash;