wgpu/lib.rs
1//! `wgpu` is a cross-platform, safe, pure-Rust graphics API. It runs natively on
2//! Vulkan, Metal, D3D12, and OpenGL; and on top of WebGL2 and WebGPU on wasm.
3//!
4//! The API is based on the [WebGPU standard][webgpu], but is a fully native Rust library.
5//! It serves as the core of the WebGPU integration in Firefox, Servo, and Deno.
6//!
7//! [webgpu]: https://gpuweb.github.io/gpuweb/
8//!
9//! ## Getting Started
10//!
11//! The main entry point to the API is the [`Instance`] type, from which you can create [`Adapter`], [`Device`], and [`Surface`].
12//!
13//! If you are new to `wgpu` and graphics programming, we recommend starting with [Learn Wgpu].
14//! <!-- Note, "Learn Wgpu" is using the capitalization style in their header, NOT our styling -->
15//!
16//! Additionally, [WebGPU Fundamentals] is a tutorial for WebGPU which is very similar to our API, minus differences between Rust and Javascript.
17//!
18//! We have a [wiki](https://github.com/gfx-rs/wgpu/wiki) which has information on useful architecture patterns, debugging tips, and more getting started information.
19//!
20//! There are examples for this version [available on GitHub](https://github.com/gfx-rs/wgpu/tree/v27/examples#readme).
21//!
22//! The API is refcounted, so all handles are cloneable, and if you create a resource which references another,
23//! it will automatically keep dependent resources alive.
24//!
25//! `wgpu` uses the coordinate systems of D3D and Metal. Depth ranges from [0, 1].
26//!
27//! | Render | Texture |
28//! | --------------------- | ---------------------- |
29//! | ![render_coordinates] | ![texture_coordinates] |
30//!
31//! `wgpu`'s MSRV is **1.88**.
32//!
33//! [Learn Wgpu]: https://sotrh.github.io/learn-wgpu/
34//! [WebGPU Fundamentals]: https://webgpufundamentals.org/
35//! [render_coordinates]: https://raw.githubusercontent.com/gfx-rs/wgpu/refs/heads/v27/docs/render_coordinates.png
36//! [texture_coordinates]: https://raw.githubusercontent.com/gfx-rs/wgpu/refs/heads/v27/docs/texture_coordinates.png
37//!
38//! ## Extension Specifications
39//!
40//! While the core of `wgpu` is based on the WebGPU standard, we also support extensions that allow for features that the standard does not have yet.
41//! For high-level documentation on how to use these extensions, see documentation on [`Features`] or the relevant specification:
42//!
43//! 🧪EXPERIMENTAL🧪 APIs are subject to change and may allow undefined behavior if used incorrectly.
44//!
45//! - 🧪EXPERIMENTAL🧪 [Ray Tracing](https://github.com/gfx-rs/wgpu/blob/v27/docs/api-specs/ray_tracing.md).
46//! - 🧪EXPERIMENTAL🧪 [Mesh Shading](https://github.com/gfx-rs/wgpu/blob/v27/docs/api-specs/mesh_shading.md).
47//!
48//! ## Shader Support
49//!
50//! `wgpu` can consume shaders in [WGSL](https://gpuweb.github.io/gpuweb/wgsl/), SPIR-V, and GLSL.
51//! Both [HLSL](https://github.com/Microsoft/DirectXShaderCompiler) and [GLSL](https://github.com/KhronosGroup/glslang)
52//! have compilers to target SPIR-V. All of these shader languages can be used with any backend as we handle all of the conversions. Additionally, support for these shader inputs is not going away.
53//!
54//! While WebGPU does not support any shading language other than WGSL, we will automatically convert your
55//! non-WGSL shaders if you're running on WebGPU.
56//!
57//! WGSL is always supported by default, but GLSL and SPIR-V need features enabled to compile in support.
58//!
59//! To enable WGSL shaders, enable the `wgsl` feature of `wgpu` (enabled by default).
60//! To enable SPIR-V shaders, enable the `spirv` feature of `wgpu`.
61//! To enable GLSL shaders, enable the `glsl` feature of `wgpu`.
62//!
63//! ## Feature flags
64#![doc = document_features::document_features!()]
65//!
66//! ### Feature Aliases
67//!
68//! These features aren't actually features on the crate itself, but a convenient shorthand for
69//! complicated cases.
70//!
71//! - **`wgpu_core`** --- Enabled when there is any non-webgpu backend enabled on the platform.
72//! - **`naga`** --- Enabled when target `glsl` or `spirv`` input is enabled, or when `wgpu_core` is enabled.
73//!
74
75#![no_std]
76#![cfg_attr(docsrs, feature(doc_cfg))]
77#![doc(html_logo_url = "https://raw.githubusercontent.com/gfx-rs/wgpu/trunk/logo.png")]
78#![warn(
79 clippy::alloc_instead_of_core,
80 clippy::allow_attributes,
81 clippy::std_instead_of_alloc,
82 clippy::std_instead_of_core,
83 missing_docs,
84 rust_2018_idioms,
85 unsafe_op_in_unsafe_fn
86)]
87#![allow(
88 // We need to investiagate these.
89 clippy::large_enum_variant,
90 // These degrade readability significantly.
91 clippy::bool_assert_comparison,
92 clippy::bool_comparison,
93)]
94// NOTE: Keep this in sync with `wgpu-core`.
95#![cfg_attr(not(send_sync), allow(clippy::arc_with_non_send_sync))]
96#![cfg_attr(not(any(wgpu_core, webgpu)), allow(unused))]
97
98extern crate alloc;
99#[cfg(std)]
100extern crate std;
101#[cfg(wgpu_core)]
102pub extern crate wgpu_core as wgc;
103#[cfg(wgpu_core)]
104pub extern crate wgpu_hal as hal;
105pub extern crate wgpu_types as wgt;
106
107//
108//
109// Modules
110//
111//
112
113mod api;
114mod backend;
115mod cmp;
116mod dispatch;
117mod macros;
118pub mod util;
119
120//
121//
122// Public re-exports
123//
124//
125
126#[cfg(custom)]
127pub use backend::custom;
128
129pub use api::*;
130pub use wgt::{
131 AdapterInfo, AddressMode, AllocatorReport, AstcBlock, AstcChannel, Backend, BackendOptions,
132 Backends, BindGroupLayoutEntry, BindingType, BlendComponent, BlendFactor, BlendOperation,
133 BlendState, BufferAddress, BufferBindingType, BufferSize, BufferTextureCopyInfo,
134 BufferTransition, BufferUsages, BufferUses, Color, ColorTargetState, ColorWrites,
135 CommandBufferDescriptor, CompareFunction, CompositeAlphaMode, CopyExternalImageDestInfo,
136 CoreCounters, DepthBiasState, DepthStencilState, DeviceLostReason, DeviceType,
137 DownlevelCapabilities, DownlevelFlags, DownlevelLimits, Dx12BackendOptions, Dx12Compiler,
138 DxcShaderModel, DynamicOffset, ExperimentalFeatures, Extent3d, ExternalTextureFormat,
139 ExternalTextureTransferFunction, Face, Features, FeaturesWGPU, FeaturesWebGPU, FilterMode,
140 FrontFace, GlBackendOptions, GlFenceBehavior, Gles3MinorVersion, HalCounters,
141 ImageSubresourceRange, IndexFormat, InstanceDescriptor, InstanceFlags, InternalCounters,
142 Limits, MemoryBudgetThresholds, MemoryHints, MipmapFilterMode, MultisampleState,
143 NoopBackendOptions, Origin2d, Origin3d, PipelineStatisticsTypes, PollError, PollStatus,
144 PolygonMode, PowerPreference, PredefinedColorSpace, PresentMode, PresentationTimestamp,
145 PrimitiveState, PrimitiveTopology, PushConstantRange, QueryType, RenderBundleDepthStencil,
146 RequestAdapterError, SamplerBindingType, SamplerBorderColor, ShaderLocation, ShaderModel,
147 ShaderRuntimeChecks, ShaderStages, StencilFaceState, StencilOperation, StencilState,
148 StorageTextureAccess, SurfaceCapabilities, SurfaceStatus, TexelCopyBufferLayout, TextureAspect,
149 TextureDimension, TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures,
150 TextureSampleType, TextureTransition, TextureUsages, TextureUses, TextureViewDimension, Trace,
151 VertexAttribute, VertexFormat, VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync,
152 COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT,
153 QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_ALIGNMENT,
154};
155
156#[expect(deprecated)]
157pub use wgt::VERTEX_STRIDE_ALIGNMENT;
158
159// wasm-only types, we try to keep as many types non-platform
160// specific, but these need to depend on web-sys.
161#[cfg(web)]
162pub use wgt::{CopyExternalImageSourceInfo, ExternalImageSource};
163
164/// Re-export of our `naga` dependency.
165///
166#[cfg(wgpu_core)]
167#[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))]
168// We re-export wgpu-core's re-export of naga, as we may not have direct access to it.
169pub use ::wgc::naga;
170/// Re-export of our `naga` dependency.
171///
172#[cfg(all(not(wgpu_core), naga))]
173#[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))]
174// If that's not available, we re-export our own.
175pub use naga;
176
177/// Re-export of our `raw-window-handle` dependency.
178///
179pub use raw_window_handle as rwh;
180
181/// Re-export of our `web-sys` dependency.
182///
183#[cfg(web)]
184pub use web_sys;
185
186#[doc(hidden)]
187pub use macros::helpers as __macro_helpers;