Expand description
wgpu is a cross-platform, safe, pure-Rust graphics API. It runs natively on
Vulkan, Metal, D3D12, and OpenGL; and on top of WebGL2 and WebGPU on wasm.
The API is based on the WebGPU standard, but is a fully native Rust library and includes many extensions specific to the native backends. It serves as the core of the WebGPU integration in Firefox, Servo, and Deno.
§Getting Started
The main entry point to the API is the Instance type, from which you can create Adapter, Device, and Surface.
If you are new to wgpu and graphics programming, we recommend starting with Learn Wgpu.
Additionally, WebGPU Fundamentals is a tutorial for WebGPU which is very similar to our API, minus differences between Rust and Javascript.
Most types and functions are documented, but for more general guides and explanations, see the documentation modules.
There are examples for this version available on GitHub.
The API is refcounted, so all handles are cloneable, and if you create a resource which references another, it will automatically keep dependent resources alive.
wgpu uses the coordinate systems of D3D and Metal. Depth ranges from [0, 1].
| Render | Texture |
|---|---|
![]() | ![]() |
wgpu’s MSRV is 1.87.
Re-exports§
pub extern crate wgpu_hal as hal;pub extern crate wgpu_core as wgc;pub extern crate wgpu_types as wgt;
Re-exports§
pub use ::wgc::naga;wgpu_coreornagapub use raw_window_handle as rwh;
Modules§
- api 🔒
- Types and functions which define our public api and their helper functionality.
- backend 🔒
- cmp 🔒
- We need to impl
PartialEq,Eq,PartialOrd,Ord, andHashfor all handle types in wgpu. - custom
custom - Provides wrappers custom backend implementations
- dispatch 🔒
- Infrastructure for dispatching calls to the appropriate “backend”. The “backends” are:
- documentation
- General documentation and guides for the
wgpucrate. - macros 🔒
- Convenience macros
- util
- Utility structures and functions that are built on top of the main
wgpuAPI.
Macros§
- include_
spirv_ raw - Macro to load raw SPIR-V data statically, for use with
Features::PASSTHROUGH_SHADERS. - include_
wgsl - Load WGSL source code from a file at compile time.
- vertex_
attr_ array - Macro to produce an array of
VertexAttribute.
Structs§
- Adapter
- Handle to a physical graphics and/or compute device.
- Adapter
Info - Information about an adapter.
- Allocator
Report - A report that can be generated for informational purposes using
Allocator::generate_report(). - Backend
Options - Options that are passed to a given backend.
- Backends
- Represents the backends that wgpu will use.
- Bind
Group - Handle to a binding group.
- Bind
Group Descriptor - Describes a group of bindings and the resources to be bound.
- Bind
Group Entry - An element of a
BindGroupDescriptor, consisting of a bindable resource and the slot to bind it to. - Bind
Group Layout - Handle to a binding group layout.
- Bind
Group Layout Descriptor - Describes a
BindGroupLayout. - Bind
Group Layout Entry - Describes a single binding inside a bind group.
- Blas
- Bottom Level Acceleration Structure (BLAS).
- Blas
Aabb Geometry - Definition for an axis-aligned bounding box geometry group for a bottom level acceleration structure.
- Blas
Async Error - Error occurred when trying to asynchronously prepare a blas for compaction.
- Blas
Build Entry - Builds the given sets of geometry into the given Blas.
- Blas
Triangle Geometry - Definition for a triangle geometry for a Bottom Level Acceleration Structure (BLAS).
- Blend
Component - Describes a blend component of a
BlendState. - Blend
State - Describe the blend state of a render pipeline,
within
ColorTargetState. - Buffer
- Handle to a GPU-accessible buffer.
- Buffer
Async Error - Error occurred when trying to async map a buffer.
- Buffer
Binding - Describes the segment of a buffer to bind.
- Buffer
Slice - A slice of a
Buffer, to be mapped, used for vertex or index data, or the like. - Buffer
Texture Copy Info - Information about a copy between a buffer and a texture.
- Buffer
Transition - A buffer transition for use with
CommandEncoder::transition_resources. - Buffer
Usages - Different ways that you can use a buffer.
- Buffer
Uses - Similar to
BufferUsages, but used only forCommandEncoder::transition_resources. - Buffer
View - A read-only view of a mapped buffer’s bytes.
- Buffer
View Mut - A write-only view of a mapped buffer’s bytes.
- Color
- RGBA double precision color.
- Color
Target State - Describes the color state of a render pipeline.
- Color
Writes - Color write mask. Disabled color channels will not be written to.
- Command
Buffer - Handle to a command buffer on the GPU.
- Command
Buffer Descriptor - Describes a
CommandBuffer. - Command
Encoder - Encodes a series of GPU operations.
- Compilation
Info - Compilation information for a shader module.
- Compilation
Message - A single message from the shader compilation process.
- Compute
Pass - In-progress recording of a compute pass.
- Compute
Pass Descriptor - Describes the attachments of a compute pass.
- Compute
Pass Timestamp Writes - Describes the timestamp writes of a compute pass.
- Compute
Pipeline - Handle to a compute pipeline.
- Compute
Pipeline Descriptor - Describes a compute pipeline.
- Context
Blas Aabb Geometry - Context version of BlasAabbGeometry.
- Context
Blas Build Entry - Context version see BlasBuildEntry.
- Context
Blas Triangle Geometry - Context version of BlasTriangleGeometry.
- Cooperative
Matrix Properties - Describes a supported cooperative matrix configuration.
- Copy
External Image Dest Info - View of a texture which can be used to copy to a texture, including color space and alpha premultiplication information.
- Core
Counters wgpu-core’s part ofInternalCounters.- Create
Surface Error Instance::create_surface()or a related function failed.- Depth
Bias State - Describes the biasing setting for the depth target.
- Depth
Stencil State - Describes the depth/stencil state in a render pipeline.
- Device
- Open connection to a graphics and/or compute device.
- Display
Chromaticity - CIE 1931 xy chromaticity of a display’s primaries and white point. Each
coordinate is
[x, y]; a coordinate the platform omits isNone. - Display
Coarse Range - Coarse, boolean dynamic-range and gamut signal.
- Display
HdrInfo - HDR and luminance characteristics of the display backing a
Surface, as reported by the platform at query time. - Display
Headroom - Relative EDR headroom (Apple): unitless multipliers over current SDR white,
where
1.0means no headroom. Moves with brightness, ambient light, battery, and which display the window is on. Apple exposes no absolute-nit equivalent, so this is separate fromDisplayLuminanceand can’t be converted to nits. - Display
Luminance - Absolute luminance levels in nits (cd/m²). Populated only on Windows (via
DXGI);
Noneon every other platform. - Downlevel
Capabilities - Lists various ways the underlying platform does not conform to the WebGPU standard.
- Downlevel
Flags - Binary flags listing features that may or may not be present on downlevel adapters.
- Downlevel
Limits - Represents the sets of additional limits on an adapter, which take place when running on downlevel backends.
- Dx12
Backend Options - Configuration for the DX12 backend.
- Error
Scope Guard - Guard for an error scope pushed with
Device::push_error_scope(). - Experimental
Features - Token of the user agreeing to access experimental features.
- Extent3d
- Extent of a texture related operation.
- External
Texture - Handle to an external texture on the GPU.
- External
Texture Transfer Function - Parameters describing a gamma encoding transfer function in the form tf = { k * linear | linear < b { a * pow(linear, 1/g) - (a-1) | linear >= b
- Features
- Features that are not guaranteed to be supported.
- FeaturesWGPU
- Features that are not guaranteed to be supported.
- Features
WebGPU - Features that are not guaranteed to be supported.
- Force
Shader Model Token - Used to force wgpu to expose certain features on passthrough shaders even when those features aren’t present on runtime-compiled shaders
- Fragment
State - Describes the fragment processing in a render pipeline.
- GlBackend
Options - Configuration for the OpenGL/OpenGLES backend.
- HalCounters
wgpu-hal’s part ofInternalCounters.- Image
Subresource Range - Subresource range within an image
- Instance
- Contains the various entry points to start interacting with the system’s GPUs.
- Instance
Descriptor - Options for creating an instance.
- Instance
Flags - Instance debugging flags.
- Internal
Counters - All internal counters, exposed for debugging purposes.
- Limits
- Represents the sets of limits an adapter/device supports.
- Load
OpDont Care - Token of the user agreeing to use
LoadOp::DontCare. - MapRange
Error - Error returned by
BufferSlice::get_mapped_rangeandBufferSlice::get_mapped_range_mut. - Memory
Budget Thresholds - Memory budget thresholds used by backends to try to avoid high memory pressure situations.
- Mesh
Pipeline Descriptor - Describes a mesh shader (graphics) pipeline.
- Mesh
State - Describes the mesh shader stage in a mesh shader pipeline.
- Multisample
State - Describes the multi-sampling state of a render pipeline.
- Noop
Backend Options - Configuration for the noop backend.
- Operations
- Pair of load and store operations for an attachment aspect.
- Origin2d
- Origin of a copy from a 2D image.
- Origin3d
- Origin of a copy to/from a texture.
- Passthrough
Shader Entry Point - Describes a single entry point in a passthrough shader descriptor.
- Pipeline
Cache - Handle to a pipeline cache, which is used to accelerate
creating
RenderPipelines andComputePipelines in subsequent executions - Pipeline
Cache Descriptor - Describes a pipeline cache, which allows reusing compilation work between program runs.
- Pipeline
Compilation Options - Advanced options for use when a pipeline is compiled
- Pipeline
Layout - Handle to a pipeline layout.
- Pipeline
Layout Descriptor - Describes a
PipelineLayout. - Pipeline
Statistics Types - Flags for which pipeline data should be recorded in a query.
- Presentation
Timestamp - Nanosecond timestamp used by the presentation engine.
- Primitive
State - Describes the state of primitive assembly and rasterization in a render pipeline.
- Query
Set - Handle to a query set.
- Queue
- Handle to a command queue on a device.
- Queue
Write Buffer View - A write-only view into a staging buffer.
- Render
Bundle - Pre-prepared reusable bundle of GPU operations.
- Render
Bundle Depth Stencil - Describes the depth/stencil attachment for render bundles.
- Render
Bundle Encoder - Encodes a series of GPU operations into a reusable “render bundle”.
- Render
Bundle Encoder Descriptor - Describes a
RenderBundleEncoder. - Render
Pass - In-progress recording of a render pass: a list of render commands in a
CommandEncoder. - Render
Pass Color Attachment - Describes a color attachment to a
RenderPass. - Render
Pass Depth Stencil Attachment - Describes a depth/stencil attachment to a
RenderPass. - Render
Pass Descriptor - Describes the attachments of a render pass.
- Render
Pass Timestamp Writes - Describes the timestamp writes of a render pass.
- Render
Pipeline - Handle to a rendering (graphics) pipeline.
- Render
Pipeline Descriptor - Describes a render (graphics) pipeline.
- Request
Adapter Options Base - Options for requesting adapter.
- Request
Device Error - Requesting a device from an
Adapterfailed. - Sampler
- Handle to a sampler.
- Shader
Module - Handle to a compiled shader module.
- Shader
Module Descriptor - Descriptor for use with
Device::create_shader_module. - Shader
Runtime Checks - Describes how shader bound checks should be performed.
- Shader
Stages - Describes the shader stages that a binding will be visible from.
- Source
Location - A human-readable representation for a span, tailored for text source.
- Stencil
Face State - Describes stencil state in a render pipeline.
- Stencil
State - State of the stencil operation (fixed-pipeline stage).
- Submission
Index - Identifier for a particular call to
Queue::submit. Can be used as part of an argument toDevice::pollto block for a particular submission to finish. - Surface
- Handle to a presentable surface.
- Surface
Capabilities - Defines the capabilities of a given surface and adapter.
- Surface
Color Spaces - A set of
SurfaceColorSpaces supported by a surface for a particular texture format. - Surface
Format Capabilities - A texture format supported by a surface, together with the color spaces in which the surface can present it.
- Surface
Texture - Surface texture that can be rendered to.
Result of a successful call to
Surface::get_current_texture. - Task
State - Describes the task shader stage in a mesh shader pipeline.
- Texel
Copy Buffer Info Base - View of a buffer which can be used to copy to/from a texture.
- Texel
Copy Buffer Layout - Layout of a texture in a buffer’s memory.
- Texel
Copy Texture Info Base - View of a texture which can be used to copy to/from a buffer/texture.
- Texture
- Handle to a texture on the GPU.
- Texture
Channel - Represents the different format channels of a texture format.
- Texture
Component Swizzle - Specifies the texture component swizzle for each channel.
- Texture
Format Feature Flags - Feature flags for a texture format.
- Texture
Format Features - Features supported by a given texture format
- Texture
Transition - A texture transition for use with
CommandEncoder::transition_resources. - Texture
Usages - Different ways that you can use a texture.
- Texture
Uses - Similar to
TextureUsages, but used only forCommandEncoder::transition_resources. - Texture
View - Handle to a texture view.
- Tlas
- Top Level Acceleration Structure (TLAS).
- Tlas
Instance - Safe instance for a Tlas.
- Vertex
Attribute - Vertex inputs (attributes) to shaders.
- Vertex
Buffer Layout - Specifies an interpretation of the bytes of a vertex buffer as vertex attributes.
- Vertex
State - Describes the vertex processing in a render pipeline.
- Wgsl
Language Features - WGSL language extensions.
- Write
Only - Like
&'a mut T, but allows only write operations. - Write
Only Iter - Iterator over the elements of
WriteOnly<[T]>.
Enums§
- Address
Mode - How edges should be handled in texture addressing.
- Astc
Block - ASTC block dimensions
- Astc
Channel - ASTC RGBA channel
- Backend
- Backends supported by wgpu.
- Binding
Resource - Resource to be bound by a
BindGroupfor use with a pipeline. - Binding
Type - Type of a binding in a bind group layout.
- Blas
Geometries - Contains the sets of geometry that go into a Blas.
- Blend
Factor - Alpha blend factor.
- Blend
Operation - Alpha blend operation.
- Buffer
Binding Type - Specific type of a buffer binding.
- Compare
Function - Comparison function used for depth and stencil operations.
- Compilation
Message Type - The type of a compilation message.
- Component
Swizzle - Specifies the component swizzle for a channel.
- Composite
Alpha Mode - Specifies how the alpha channel of the textures should be handled during compositing.
- Context
Blas Geometries - Context version of BlasGeometries.
- Cooperative
Scalar Type - The underlying scalar type of the cooperative matrix component.
- Current
Surface Texture - Result of a call to
Surface::get_current_texture. - Device
Lost Reason - Corresponds to a
GPUDeviceLostReason. - Device
Type - Supported physical device types.
- Display
Gamut - Coarse gamut classification, mirroring CSS
color-gamut. - Dx12
Compiler - Selects which DX12 shader compiler to use.
- Dx12
Swapchain Kind - Selects which kind of swapchain to use on DX12.
- Dx12
UseFrame Latency Waitable Object - Whether and how to use a waitable handle obtained from
GetFrameLatencyWaitableObject. - DxcShader
Model - DXC shader model.
- Error
- Errors resulting from usage of GPU APIs.
- Error
Filter - Kinds of
Errors apush_error_scopemay be configured to catch. - Error
Type - A classification of WebGPU error for implementers of the WebGPU API to use in their own error layer(s).
- External
Texture Format - Format of an
ExternalTexture. This indicates the number of underlying planes used by theExternalTextureas well as each plane’s format. - Face
- Face of a vertex.
- Filter
Mode - Texel mixing mode when sampling between texels.
- Front
Face - Vertex winding order which classifies the “front” face of a triangle.
- GlDebug
Fns - Controls whether OpenGL debug functions are enabled.
- GlFence
Behavior - Dictate the behavior of fences in OpenGL.
- Gles3
Minor Version - Selects which OpenGL ES 3 minor version to request.
- Index
Format - Format of indices used with pipeline.
- LoadOp
- Operation to perform to the output attachment at the start of a render pass.
- MapMode
- Type of buffer mapping.
- Memory
Hints - Hints to the device about the memory allocation strategy.
- Mipmap
Filter Mode - Texel mixing mode when sampling between texels.
- Poll
Error - Error states after a device poll.
- Poll
Status - Status of device poll operation.
- Polygon
Mode - Type of drawing mode for polygons
- Power
Preference - Power Preference when choosing a physical adapter.
- Predefined
Color Space - Color spaces supported on the web.
- Present
Mode - Timing and queueing with which frames are actually displayed to the user.
- Primitive
Topology - Primitive type the input mesh is composed of.
- Query
Type - Type of queries contained in a
QuerySet. - Request
Adapter Error - Error when
Instance::request_adapter()fails. - Sampler
Binding Type - Specific type of a sampler binding.
- Sampler
Border Color - Color variation to use when sampler addressing mode is
AddressMode::ClampToBorder - Shader
Model - Collections of shader features a device supports if they support less than WebGPU normally allows.
- Shader
Source - Source of a shader module.
- Stencil
Operation - Operation to perform on the stencil value.
- Storage
Texture Access - Specific type of a sample in a texture binding.
- StoreOp
- Operation to perform to the output attachment at the end of a render pass.
- Surface
Color Space - The color space in which the presentation engine interprets the values written to a surface texture.
- Surface
Status - Status of the received surface image.
- Surface
Target - The window/canvas/surface/swap-chain/etc. a surface is attached to, for use with safe surface creation.
- Surface
Target Unsafe - The window/canvas/surface/swap-chain/etc. a surface is attached to, for use with unsafe surface creation.
- Texture
Aspect - Selects a subset of the data a
Textureholds. - Texture
Dimension - Dimensionality of a texture.
- Texture
Format - Format in which a texture’s texels are stored in GPU memory.
- Texture
Sample Type - Specific type of a sample in a texture binding.
- Texture
View Dimension - Dimensions of a particular texture view.
- Trace
- Controls API call tracing and specifies where the trace is written.
- Vertex
Format - Corresponds to WebGPU
GPUVertexFormat. - Vertex
Step Mode - Whether a vertex buffer is indexed by vertex or by instance.
Constants§
- AABB_
GEOMETRY_ MIN_ STRIDE - Minimum stride for AABB geometry (24 bytes: two
vec3<f32>). Minimum stride for AABB geometry (24 bytes: twovec3<f32>). - COPY_
BUFFER_ ALIGNMENT - Buffer to buffer copy as well as buffer clear offsets and sizes must be aligned to this number.
- COPY_
BYTES_ PER_ ROW_ ALIGNMENT - Buffer-texture copies must have
bytes_per_rowaligned to this number. - IMMEDIATE_
DATA_ ALIGNMENT - Ranges of writes to immediate data must be at least this aligned.
- MAP_
ALIGNMENT - Minimum alignment of buffer mappings.
- MAXIMUM_
SUBGROUP_ MAX_ SIZE - The maximum allowed value for
AdapterInfo::subgroup_max_size. - MINIMUM_
SUBGROUP_ MIN_ SIZE - The minimum allowed value for
AdapterInfo::subgroup_min_size. - QUERY_
RESOLVE_ BUFFER_ ALIGNMENT - An offset into the query resolve buffer has to be aligned to this.
- QUERY_
SET_ MAX_ QUERIES - Maximum number of query result slots that can be requested in a [
QuerySetDescriptor]. - QUERY_
SIZE - Size in bytes of a single piece of query data.
- VERTEX_
ALIGNMENT - Vertex buffer offsets and strides have to be a multiple of this number.
- VERTEX_
STRIDE_ ALIGNMENT Deprecated - Vertex buffer strides have to be a multiple of this number.
Traits§
- Display
AndWindow Handle - Super trait for a pair of display and window handles as used in
SurfaceTarget. - Uncaptured
Error Handler - The callback of
uncaptured_error - Wasm
NotSend - Wasm
NotSend Sync - Wasm
NotSync - WebGpu
Error - A trait for querying the
ErrorTypeclassification of an error. - Window
Handle Send/Syncblanket trait for [HasWindowHandle] used inSurfaceTarget.
Type Aliases§
- Acceleration
Structure Flags - Flags for an acceleration structure.
- Acceleration
Structure Geometry Flags - Flags for a geometry inside a bottom level acceleration structure.
- Acceleration
Structure Update Mode - Update mode for acceleration structure builds.
- BlasAABB
Geometry Size Descriptor - Descriptor for the size defining attributes of an AABB geometry group in a bottom level acceleration structure.
- Blas
Geometry Size Descriptors - Descriptor for the size defining attributes, for a bottom level acceleration structure.
- Blas
Triangle Geometry Size Descriptor - Descriptor for the size defining attributes of a triangle geometry, for a bottom level acceleration structure.
- Buffer
Address - Integral type used for
Bufferoffsets and sizes. - Buffer
Descriptor - Describes a
Buffer. - Buffer
Size - Integral type used for
BufferSlicesizes. - Command
Encoder Descriptor - Describes a
CommandEncoder. - Create
Blas Descriptor - Descriptor to create bottom level acceleration structures.
- Create
Tlas Descriptor - Descriptor to create top level acceleration structures.
- Device
Descriptor - Describes a
Device. - Dynamic
Offset - Integral type used for dynamic bind group offsets.
- Error
Source Non- target_family=wasm, orfragile-send-sync-non-atomic-wasmand non-atomics - Lower level source of the error.
- External
Texture Descriptor - Describes an
ExternalTexture. - Label
- Object debugging label.
- Poll
Type - Passed to
Device::pollto control how and if it should block. - Query
SetDescriptor - Describes a
QuerySet. - Queue
Descriptor - Describes a
Queue. - Render
Bundle Descriptor - Describes a
RenderBundle. - Request
Adapter Options - Additional information required when requesting an adapter.
- Sampler
Descriptor - Describes a
Sampler. - Shader
Location - Integral type used for binding locations in shaders.
- Shader
Module Descriptor Passthrough - Descriptor for a shader module given by any of several sources.
At least one of the shader types that may be used by the backend must be
Some - Surface
Configuration - Describes a
Surface. - Texel
Copy Buffer Info - View of a buffer which can be used to copy to/from a texture.
- Texel
Copy Texture Info - View of a texture which can be used to copy to/from a buffer/texture.
- Texture
Descriptor - Describes a
Texture. - Texture
View Descriptor - Describes a
TextureView.

