Skip to content

Commit 1e9bec7

Browse files
authored
Explainer: initialization (#1636)
* Explainer: initialization * clarify similarity to WebGLRenderingContext
1 parent 8542a4f commit 1e9bec7

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

explainer/index.bs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,52 @@ See also the description of [the content and device timelines in the specificati
5656

5757
## Adapter Selection and Device Init ## {#initialization}
5858

59+
Issue: Some changes are expected here.
60+
61+
A WebGPU "adapter" (`GPUAdapter`) is an object which provides a connection to a particular WebGPU
62+
implementation on the system (e.g. a hardware accelerated implementation on an integrated or
63+
discrete GPU, or software implementation).
64+
To get a `GPUAdapter` is to select which implementation to use (if multiple are available).
65+
66+
Each adapter may have different optional capabilities called "features" and "limits".
67+
These are the maximum possible capabilities that can be requested when a device is created.
68+
69+
To get an adapter, an application calls `navigator.gpu.requestAdapter()`, optionally passing
70+
options which may influence what adapter is chosen.
71+
72+
`requestAdapter()` always resolves, but may resolve to null if an adapter can't be returned with
73+
the specified options.
74+
75+
<pre highlight=js>
76+
const adapter = await navigator.gpu.requestAdapter(options);
77+
if (!adapter) return goToFallback();
78+
</pre>
79+
80+
A WebGPU "device" (`GPUDevice`) represents a connection to a WebGPU implementation, as well as
81+
an arena for all WebGPU objects created from it (textures, command buffers, etc.)
82+
All WebGPU usage is done through a WebGPU "device" (`GPUDevice`) or objects created from it.
83+
In this sense, it serves a subset of the purpose of `WebGLRenderingContext`; however, unlike
84+
`WebGLRenderingContext`, it is not associated with a canvas object, and most commands are
85+
issued through "child" objects.
86+
87+
To get a device, an application calls `adapter.requestDevice()`, optionally passing a descriptor
88+
which enables additional optional capabilities (features and limits).
89+
When any work is issued to the device, it is strictly validated against the capabilities passed
90+
to `requestDevice()` - not the capabilities of the adapter.
91+
92+
`requestDevice()` will reject (only) if the request exceeds the capabilities of the adapter.
93+
It may *not* resolve to `null`; instead, to simplify the number of different cases an app must
94+
handle, it may resolve to a `GPUDevice` which has already been lost - see [[#device-loss]].
95+
96+
<pre highlight=js>
97+
const device = await adapter.requestDevice(descriptor);
98+
device.lost.then(recoverFromDeviceLoss);
99+
</pre>
100+
101+
An adapter may become unavailable, e.g. if it is unplugged from the system, disabled to save
102+
power, or marked "stale" (`[[current]]` becomes false).
103+
Such an adapter can no longer vend valid devices, and always returns already-lost `GPUDevice`s.
104+
59105

60106
## Object Validity and Destroyed-ness ## {#invalid-and-destroyed}
61107

@@ -395,7 +441,7 @@ For example:
395441
```
396442

397443

398-
## Adapter and Device Loss ## {#device-loss}
444+
## Device Loss ## {#device-loss}
399445

400446
Any situation that prevents further use of a `GPUDevice`, regardless of whether it is caused by a
401447
WebGPU call (e.g. `device.destroy()`, unrecoverable out-of-memory, GPU process crash, or GPU
@@ -983,6 +1029,7 @@ which mentions that strongly-typed bitflags in JavaScript would be useful.
9831029

9841030
# WebGPU Shading Language # {#wgsl}
9851031

1032+
9861033
# Security and Privacy self-review # {#questionnaire}
9871034

9881035
## What information might this feature expose to Web sites or other parties, and for what purposes is that exposure necessary? ## {#questionnaire-1}
@@ -1063,7 +1110,7 @@ However WebGPU can be used to render to fullscreen or WebXR which does change th
10631110
WebGPU can also run GPU computations that take too long and cause of device timeout and a restart of GPU (TDR), which can produce a couple system-wide black frames.
10641111
Note that this is possible with "just" HTML / CSS but WebGPU makes it easier to cause a TDR.
10651112

1066-
## What temporary identifiers do the features in this specification create or expose to the web?## {#questionnaire-13}
1113+
## What temporary identifiers do the features in this specification create or expose to the web? ## {#questionnaire-13}
10671114

10681115
None.
10691116

0 commit comments

Comments
 (0)