WebGPU API Reference
These pages list the WebGPU interfaces used by the tutorials. Each page stays with members that exist in the specification. The complete definitions are in the WebGPU specification.
From the adapter to the queue
Section titled “From the adapter to the queue”interface GPU { requestAdapter(options?: GPURequestAdapterOptions): Promise<GPUAdapter | null>; getPreferredCanvasFormat(): GPUTextureFormat;}
interface GPUAdapter { readonly features: GPUSupportedFeatures; readonly limits: GPUSupportedLimits; readonly info: GPUAdapterInfo; requestDevice(descriptor?: GPUDeviceDescriptor): Promise<GPUDevice>;}GPUDevice creates the resources. Common methods:
| Method | Object |
|---|---|
createBuffer | GPUBuffer |
createTexture | GPUTexture |
createSampler | GPUSampler |
createBindGroupLayout / createBindGroup | GPUBindGroup |
createPipelineLayout | Combines bind group layouts into a pipeline layout |
createShaderModule | Compiles WGSL |
createRenderPipeline | GPURenderPipeline |
createComputePipeline | GPUComputePipeline |
createCommandEncoder | GPUCommandEncoder |
pushErrorScope / popErrorScope | Capture validation errors |
destroy | Destroy the device and resources it created |
The device also exposes read-only features, limits, and queue. lost is a promise that resolves when the device is lost. Validation errors that are not captured by an error scope are delivered as uncapturederror events.
getPreferredCanvasFormat() returns only "rgba8unorm" or "bgra8unorm". Use that value for the canvas color attachment and the fragment target format.
How resources reach a shader
Section titled “How resources reach a shader”- Vertex and index data are buffers, bound with
setVertexBuffer()andsetIndexBuffer(). - Uniforms, storage buffers, textures, and samplers go in a bind group and are bound with
setBindGroup(). - Commands are recorded into a
GPUCommandEncoder.finish()returns aGPUCommandBuffer, andGPUQueue.submit()runs it.
Tutorial order:
- WGSL basics
- Render pipeline
- Buffers
- Bind groups
- Uniform buffers
- Textures and samplers
- Depth buffer
- Compute shaders