Expand description
A cross-platform graphics and compute library based on WebGPU.
To start using the API, create an Instance
.
§Feature flags
§Backends
dx12
(enabled by default) — Enables the DX12 backend on Windows.metal
(enabled by default) — Enables the Metal backend on macOS & iOS.vulkan
(enabled by default) — Enables the Vulkan backend on Windows, Linux, and Android.gles
(enabled by default) — Enables the OpenGL/GLES backend on Windows, Linux, Android, and Emscripten.webgpu
(enabled by default) — Enables the WebGPU backend on WebAssembly.
§Conditional Backends
-
angle
— Enables the GLES backend on macOS only for use with ANGLE. -
vulkan-portability
— Enables the Vulkan backend on macOS & iOS only for use with MoltenVK. -
webgl
— Enables the GLES backend on WebAssembly only. -
noop
— Enables the noop backend for testing.This backend allows creating resources such as buffers and textures, but performs no computation. Because it lacks basic functionality, it is only actually used if explicitly enabled through
NoopBackendOptions
.
Note: In the documentation, if you see that an item depends on a backend, it means that the item is only available when that backend is enabled and the backend is supported on the current platform.
§Shading language support
These features enable support for that input language on all platforms. We will translate the input language to whatever the backend requires.
spirv
— Enable accepting SPIR-V shaders as input.glsl
— Enable accepting GLSL shaders as input.wgsl
(enabled by default) — Enable accepting WGSL shaders as input.naga-ir
— Enable accepting naga IR shaders as input.
§Assertions and Serialization
strict_asserts
— Apply run-time checks, even in release builds. These are in addition to the validation carried out at public APIs in all builds.serde
— Enables serialization viaserde
on common wgpu types.
§External libraries
The following features facilitate integration with third-party supporting libraries.
-
static-dxc
— Enables statically linking DXC.Normally, to use the modern DXC shader compiler with WGPU, the final application must be shipped alongside
dxcompiler.dll
anddxil.dll
(which can be downloaded from Microsoft’s GitHub). This feature statically links a version of DXC so that no external binaries are required to compile DX12 shaders.
§Other
-
counters
— Internally count resources and events for debugging purposes. If the counters feature is disabled, the counting infrastructure is removed from the build and the exposed counters always return 0. -
fragile-send-sync-non-atomic-wasm
— ImplementSend
andSync
on Wasm, but only if atomics are not enabled.WebGL/WebGPU objects can not be shared between threads. However, it can be useful to artificially mark them as
Send
andSync
anyways to make it easier to write cross-platform code. This is technically very unsafe in a multithreaded environment, but on a wasm binary compiled without atomics is a definitionally single-threaded environment.
§Feature Aliases
These features aren’t actually features on the crate itself, but a convenient shorthand for complicated cases.
wgpu_core
— Enabled when there is any non-webgpu backend enabled on the platform.naga
–– Enabled when any non-wgsl shader input is enabled.
Re-exports§
pub extern crate wgpu_hal as hal;
pub extern crate wgpu_core as wgc;
pub extern crate wgpu_types as wgt;
pub use ::wgc::naga;
wgpu_core
ornaga
pub use raw_window_handle as rwh;
Modules§
- custom
custom
- Provides wrappers custom backend implementations
- util
- Utility structures and functions that are built on top of the main
wgpu
API.
Macros§
- include_
spirv spirv
- Macro to load a SPIR-V module statically.
- include_
spirv_ raw - Macro to load raw SPIR-V data statically, for use with
Features::SPIRV_SHADER_PASSTHROUGH
. - 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
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
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 Build Entry - Context version see BlasBuildEntry.
- Context
Blas Triangle Geometry - Context version of BlasTriangleGeometry.
- 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.
- 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.
- Extent3d
- Extent of a texture related operation.
- 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.
- 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
- Context for all other wgpu objects. Instance of wgpu.
- 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.
- 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.
- Pipeline
Cache - Handle to a pipeline cache, which is used to accelerate
creating
RenderPipeline
s andComputePipeline
s 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.
- Push
Constant Range - A range of push constant memory to pass to a shader stage.
- 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
Adapter
failed. - 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::poll
to 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
Texture - Surface texture that can be rendered to.
Result of a successful call to
Surface::get_current_texture
. - 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
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
Build Entry - Entry for a top level acceleration structure build.
Used with raw instance buffers for an unvalidated builds.
See
TlasPackage
for the safe version. - Tlas
Instance - Safe instance for a Tlas.
- Tlas
Package - The safe version of
TlasBuildEntry
, containingTlasInstance
s instead of a raw buffer. - 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.
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
BindGroup
for 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.
- Composite
Alpha Mode - Specifies how the alpha channel of the textures should be handled during compositing.
- Context
Blas Geometries - Context version of BlasGeometries.
- Device
Lost Reason - Reason for “lose the device”.
- Device
Type - Supported physical device types.
- Dx12
Compiler - Selects which DX12 shader compiler to use.
- DxcShader
Model - DXC shader model.
- Error
- Errors resulting from usage of GPU APIs.
- Error
Filter - Kinds of
Error
s aDevice::push_error_scope()
may be configured to catch. - 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.
- 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.
- Maintain
Base - Passed to
Device::poll
to control how and if it should block. - MapMode
- Type of buffer mapping.
- Memory
Hints - Hints to the device about the memory allocation strategy.
- 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 query 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
Error - Result of an unsuccessful call to
Surface::get_current_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
Texture
holds. - 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 - Vertex Format for a
VertexAttribute
(input). - Vertex
Step Mode - Whether a vertex buffer is indexed by vertex or by instance.
Constants§
- 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-to-texture copies must have
bytes_per_row
aligned to this number. - MAP_
ALIGNMENT - Minimum alignment of buffer mappings.
- PUSH_
CONSTANT_ ALIGNMENT - Ranges of writes to push constant storage must be at least this aligned.
- QUERY_
RESOLVE_ BUFFER_ ALIGNMENT - An offset into the query resolve buffer has to be aligned to this.
- QUERY_
SET_ MAX_ QUERIES - Maximum queries in a
QuerySetDescriptor
. - QUERY_
SIZE - Size in bytes of a single piece of query data.
- VERTEX_
STRIDE_ ALIGNMENT - Vertex buffer strides have to be a multiple of this number.
Traits§
- Uncaptured
Error Handler - Type for the callback of uncaptured error handler
- Wasm
NotSend - Wasm
NotSend Sync - Wasm
NotSync - Window
Handle - Super trait for window handles as used in
SurfaceTarget
.
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.
- 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
Buffer
offsets and sizes. - Buffer
Descriptor - Describes a
Buffer
. - Buffer
Size - Integral type used for
BufferSlice
sizes. - 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 - Lower level source of the error.
- Image
Copy Buffer Deprecated - Old name for a
TexelCopyBufferInfo
. - Image
Copy Texture Deprecated - Old name for a
TexelCopyTextureInfo
. - Image
Copy Texture Tagged Deprecated - Old name for a
CopyExternalImageDestInfo
. - Image
Data Layout Deprecated - Old name for a
TexelCopyBufferLayout
. - Label
- Object debugging label.
- Poll
Type - Passed to
Device::poll
to control how and if it should block. - Query
SetDescriptor - Describes a
QuerySet
. - 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 Msl - Descriptor for a shader module given by Metal MSL source.
- Shader
Module Descriptor Passthrough - Descriptor for a shader module that will bypass wgpu’s shader tooling, for use with
Device::create_shader_module_passthrough
. - Shader
Module Descriptor SpirV - Descriptor for a shader module given by SPIR-V binary.
- 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
.