Limited availability
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
The GPU
interface of the WebGPU API is the starting point for using WebGPU. It can be used to return a GPUAdapter
from which you can request devices, configure features and limits, and more.
The GPU
object for the current context is accessed via the Navigator.gpu
or WorkerNavigator.gpu
properties.
wgslLanguageFeatures
Read only
A WGSLLanguageFeatures
object that reports the WGSL language extensions supported by the WebGPU implementation.
requestAdapter()
Returns a Promise
that fulfills with a GPUAdapter
object instance. From this you can request a GPUDevice
, which is the primary interface for using WebGPU functionality.
getPreferredCanvasFormat()
Returns the optimal canvas texture format for displaying 8-bit depth, standard dynamic range content on the current system.
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();
// â¦
}
Configuring a GPUCanvasContext with the optimal texture format
const canvas = document.querySelector("#gpuCanvas");
const context = canvas.getContext("webgpu");
context.configure({
device,
format: navigator.gpu.getPreferredCanvasFormat(),
alphaMode: "premultiplied",
});
Specifications Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4