W3cubDocs

/Web APIs

GPUDevice

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The GPUDevice interface of the WebGPU API represents a logical GPU device. This is the main interface through which the majority of WebGPU functionality is accessed.

A GPUDevice object is requested using the GPUAdapter.requestDevice() method.

EventTarget GPUDevice

Instance properties

Inherits properties from its parent, EventTarget.

features Experimental Read only

A GPUSupportedFeatures object that describes additional functionality supported by the device.

label Experimental

A string providing a label that can be used to identify the object, for example in GPUError messages or console warnings.

limits Experimental Read only

A GPUSupportedLimits object that describes the limits supported by the device.

lost Experimental Read only

Contains a Promise that remains pending throughout the device's lifetime and resolves with a GPUDeviceLostInfo object when the device is lost.

queue Experimental Read only

Returns the primary GPUQueue for the device.

Instance methods

Inherits methods from its parent, EventTarget.

createBindGroup() Experimental

Creates a GPUBindGroup based on a GPUBindGroupLayout that defines a set of resources to be bound together in a group and how those resources are used in shader stages.

createBindGroupLayout() Experimental

Creates a GPUBindGroupLayout that defines the structure and purpose of related GPU resources such as buffers that will be used in a pipeline, and is used as a template when creating GPUBindGroups.

createBuffer() Experimental

Creates a GPUBuffer in which to store raw data to use in GPU operations.

createCommandEncoder() Experimental

Creates a GPUCommandEncoder, which is used to encode commands to be issued to the GPU.

createComputePipeline() Experimental

Creates a GPUComputePipeline that can control the compute shader stage and be used in a GPUComputePassEncoder.

createComputePipelineAsync() Experimental

Returns a Promise that fulfills with a GPUComputePipeline, which can control the compute shader stage and be used in a GPUComputePassEncoder, once the pipeline can be used without any stalling.

createPipelineLayout() Experimental

Creates a GPUPipelineLayout that defines the GPUBindGroupLayouts used by a pipeline. GPUBindGroups used with the pipeline during command encoding must have compatible GPUBindGroupLayouts.

createQuerySet() Experimental

Creates a GPUQuerySet that can be used to record the results of queries on passes, such as occlusion or timestamp queries.

createRenderBundleEncoder() Experimental

Creates a GPURenderBundleEncoder that can be used to pre-record bundles of commands. These can be reused in GPURenderPassEncoders via the executeBundles() method, as many times as required.

createRenderPipeline() Experimental

Creates a GPURenderPipeline that can control the vertex and fragment shader stages and be used in a GPURenderPassEncoder or GPURenderBundleEncoder.

createRenderPipelineAsync() Experimental

Returns a Promise that fulfills with a GPURenderPipeline, which can control the vertex and fragment shader stages and be used in a GPURenderPassEncoder or GPURenderBundleEncoder, once the pipeline can be used without any stalling.

createSampler() Experimental

Creates a GPUSampler, which controls how shaders transform and filter texture resource data.

createShaderModule() Experimental

Creates a GPUShaderModule from a string of WGSL source code.

createTexture() Experimental

Creates a GPUTexture in which to store texture data to use in GPU rendering operations.

destroy() Experimental

Destroys the device, preventing further operations on it.

importExternalTexture() Experimental

Takes an HTMLVideoElement as an input and returns a GPUExternalTexture wrapper object containing a snapshot of the video that can be used in GPU rendering operations.

popErrorScope() Experimental

Pops an existing GPU error scope from the error scope stack and returns a Promise that resolves to an object (GPUInternalError, GPUOutOfMemoryError, or GPUValidationError) describing the first error captured in the scope, or null if no error occurred.

pushErrorScope() Experimental

Pushes a new GPU error scope onto the device's error scope stack, allowing you to capture errors of a particular type.

Events

uncapturederror Experimental

Fired when an error is thrown that has not been observed by a GPU error scope, to provide a way to report unexpected errors. Known error cases should be handled using pushErrorScope() and popErrorScope().

Examples

js

async function init() {
  if (!navigator.gpu) {
    throw Error("WebGPU not supported.");
  }

  const adapter = await navigator.gpu.requestAdapter();
  if (!adapter) {
    throw Error("Couldn't request WebGPU adapter.");
  }

  const device = await adapter.requestDevice();

  const shaderModule = device.createShaderModule({
    code: shaders,
  });

  //...
}

See the individual member pages listed above and the following demo sites for a lot more examples of GPUDevice usage:

Specifications

Specification
WebGPU
# gpudevice

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
GPUDevice
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createBindGroup
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createBindGroupLayout
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createBuffer
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createCommandEncoder
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createComputePipeline
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createComputePipelineAsync
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createPipelineLayout
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createQuerySet
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
No No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createRenderBundleEncoder
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createRenderPipeline
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createRenderPipelineAsync
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createSampler
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createShaderModule
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
createTexture
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
destroy
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
features
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
importExternalTexture
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
label
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
limits
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
lost
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
popErrorScope
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
pushErrorScope
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
queue
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No
uncapturederror_event
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
previewCurrently supported on Linux and Windows only.
No
99Currently supported on ChromeOS, macOS, and Windows only.
No No No No No No No

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/GPUDevice