WebGPU extension
The WebGPU extension (ext/webgpu/) implements the WebGPU API specification in Deno, enabling hardware-accelerated graphics and compute capabilities through the GPU.
Overview
WebGPU is a modern graphics and compute API that provides access to GPU capabilities in a cross-platform way. Deno’s implementation is built on top of wgpu, Mozilla’s safe, portable GPU abstraction library written in Rust.The WebGPU spec is still in development. Deno’s implementation targets the spec draft as of March 31, 2024, and is updated regularly as the specification evolves.
Key features
GPU compute
Run high-performance compute workloads on the GPU
3D graphics
Render 3D graphics and visualizations
Cross-platform
Works across different operating systems and GPU vendors
Safe by default
Built on wgpu for memory safety and portability
Basic usage
Requesting a GPU adapter
Creating a device
GPU compute example
WebGPU API components
The extension implements the full WebGPU specification, including:Core interfaces
navigator.gpu- Entry point for WebGPUGPUAdapter- Represents a GPU adapterGPUDevice- Represents a logical GPU deviceGPUQueue- Command submission queue
Resources
GPUBuffer- GPU-accessible data storageGPUTexture- Image data storageGPUSampler- Texture sampling configuration
Shaders and pipelines
GPUShaderModule- Compiled shader codeGPURenderPipeline- Graphics rendering pipelineGPUComputePipeline- Compute shader pipeline
Command encoding
GPUCommandEncoder- Records GPU commandsGPURenderPassEncoder- Records rendering commandsGPUComputePassEncoder- Records compute commandsGPURenderBundle- Pre-recorded rendering commands
Binding resources
GPUBindGroupLayout- Describes resource binding layoutGPUBindGroup- Binds resources to a pipelineGPUPipelineLayout- Complete pipeline resource layout
Query and synchronization
GPUQuerySet- Performance queriesGPUFence- GPU synchronization (deprecated in favor of promises)
Debugging
Set the
DENO_WEBGPU_TRACE environment variable to output a wgpu trace to a specified directory for debugging.Testing
Deno’s WebGPU implementation is tested using:- WebGPU Conformance Test Suite (CTS)
- wgpu’s
cts_runner - Directed tests for missing coverage
Resources
WebGPU specification
Official WebGPU API specification
Design documents
WebGPU design documentation
Conformance tests
WebGPU CTS test suite
WebGPU examples
WebGPU examples for Deno
Community
For help with WebGPU development:- wgpu-users Matrix channel: https://matrix.to/#/#wgpu-users:matrix.org
- Deno Discord: https://discord.gg/deno