web api interface
GPUDevice
Secure contextAvailable in workers
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 requestDevice() method.
Instance properties
Inherits properties from its parent, EventTarget.
-
adapterInfoRead only- : A
GPUAdapterInfoobject containing identifying information about the device’s originating adapter.
- : A
-
featuresRead only- : A
GPUSupportedFeaturesobject that describes additional functionality supported by the device.
- : A
-
- : A string providing a label that can be used to identify the object, for example in
GPUErrormessages or console warnings.
- : A string providing a label that can be used to identify the object, for example in
-
limitsRead only- : A
GPUSupportedLimitsobject that describes the limits supported by the device.
- : A
-
lostRead only- : Contains a
Promisethat remains pending throughout the device’s lifetime and resolves with aGPUDeviceLostInfoobject when the device is lost.
- : Contains a
-
queueRead only- : Returns the primary
GPUQueuefor the device.
- : Returns the primary
Instance methods
Inherits methods from its parent, EventTarget.
-
- : Creates a
GPUBindGroupbased on aGPUBindGroupLayoutthat defines a set of resources to be bound together in a group and how those resources are used in shader stages.
- : Creates a
-
- : Creates a
GPUBindGroupLayoutthat 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 creatingGPUBindGroups.
- : Creates a
-
- : Creates a
GPUBufferin which to store raw data to use in GPU operations.
- : Creates a
-
- : Creates a
GPUCommandEncoder, which is used to encode commands to be issued to the GPU.
- : Creates a
-
- : Creates a
GPUComputePipelinethat can control the compute shader stage and be used in aGPUComputePassEncoder.
- : Creates a
-
- : Returns a
Promisethat fulfills with aGPUComputePipeline, which can control the compute shader stage and be used in aGPUComputePassEncoder, once the pipeline can be used without any stalling.
- : Returns a
-
- : Creates a
GPUPipelineLayoutthat defines theGPUBindGroupLayouts used by a pipeline.GPUBindGroups used with the pipeline during command encoding must have compatibleGPUBindGroupLayouts.
- : Creates a
-
- : Creates a
GPUQuerySetthat can be used to record the results of queries on passes, such as occlusion or timestamp queries.
- : Creates a
-
- : Creates a
GPURenderBundleEncoderthat can be used to pre-record bundles of commands. These can be reused inGPURenderPassEncoders via theexecuteBundles()method, as many times as required.
- : Creates a
-
- : Creates a
GPURenderPipelinethat can control the vertex and fragment shader stages and be used in aGPURenderPassEncoderorGPURenderBundleEncoder.
- : Creates a
-
- : Returns a
Promisethat fulfills with aGPURenderPipeline, which can control the vertex and fragment shader stages and be used in aGPURenderPassEncoderorGPURenderBundleEncoder, once the pipeline can be used without any stalling.
- : Returns a
-
- : Creates a
GPUSampler, which controls how shaders transform and filter texture resource data.
- : Creates a
-
- : Creates a
GPUShaderModulefrom a string of WGSL source code.
- : Creates a
-
- : Creates a
GPUTexturein which to store texture data to use in GPU rendering operations.
- : Creates a
-
- : Destroys the device, preventing further operations on it.
-
- : Takes an
HTMLVideoElementas an input and returns aGPUExternalTexturewrapper object containing a snapshot of the video that can be used in GPU rendering operations.
- : Takes an
-
- : Pops an existing GPU error scope from the error scope stack and returns a
Promisethat resolves to an object (GPUInternalError,GPUOutOfMemoryError, orGPUValidationError) describing the first error captured in the scope, ornullif no error occurred.
- : Pops an existing GPU error scope from the error scope stack and returns a
-
- : Pushes a new GPU error scope onto the device’s error scope stack, allowing you to capture errors of a particular type.
Events
uncapturederror- : 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()andpopErrorScope().
- : 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
Examples
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
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.
See also
- The WebGPU API