Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions design/ErrorHandling.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Meanwhile, error handling should not make the API clunky to use.
Implementations should provide a way to enable synchronous validation, for example via a "break on WebGPU error" option in the developer tools.
The extra overhead needs to be low enough that applications can still run while being debugged.

## *Fatal Errors*: requestDevice and device.lost
## *Fatal Errors*: requestAdapters, requestDevice, and device.lost

<!-- calling this revision 6 -->

Expand Down Expand Up @@ -96,8 +96,9 @@ class MyRenderer {
async ensureAdapter() {
if (!this.adapter) {
// If no adapter, get one.
// (If requestAdapter rejects, no matching adapter is available. Exit to fallback.)
this.adapter = await gpu.requestAdapter({ /* options */ });
// (If requestAdapters rejects, no matching adapter is available. Exit to fallback.)
const adapters = await navigator.gpu.requestAdapters({ /* options */ });
this.adapter = adapters[0]; // (Or, manually search through the returned adapters.)
}
}
async ensureDeviceOnCurrentAdapter() {
Expand Down Expand Up @@ -134,17 +135,21 @@ A page begins loading in a tab, but then the tab is backgrounded.

A device's adapter is physically unplugged from the system (but an integrated GPU is still available).
- The same adapter, or a new adapter, is plugged back in.
- A later `requestAdapter` call may return the new adapter. (In the future, it might fire a "gpuadapterschanged" event.)
- A later `requestAdapters` call may return the new adapter.
(In the future, it might fire a "gpuadapterschanged" event.)

An app is running on an integrated adapter.
- A new, discrete adapter is plugged in.
- A later `requestAdapter` call may return the new adapter. (In the future, it might fire a "gpuadapterschanged" event.)
- A later `requestAdapters` call may return the new adapter.
(In the future, it might fire a "gpuadapterschanged" event.)

An app is running on a discrete adapter.
- The adapter is physically unplugged from the system. An integrated GPU is still available.
- `device.lost` resolves, `requestDevice` on same adapter rejects, `requestAdapter` gives the new adapter.
- `device.lost` resolves, `requestDevice` on same adapter rejects, `requestAdapters`
returns a new list excluding the discrete GPU, and including the integrated GPU.
- The same adapter, or a new adapter, is plugged back in.
- A later `requestAdapter` call may return the new adapter. (In the future, it might fire a "gpuadapterschanged" event.)
- A later `requestAdapters` call may return the new adapter.
(In the future, it might fire a "gpuadapterschanged" event.)

The device is lost because of an unexpected error in the implementation.
- `device.lost` resolves, message = whatever the unexpected thing was.
Expand All @@ -158,7 +163,7 @@ All devices and adapters are lost (except for software?) because GPU access has
- `device.lost` resolves on every device, message = whatever

WebGPU access has been disabled for the page.
- `requestAdapter` rejects (or returns a software adapter).
- `requestAdapters` rejects (or returns a software adapter).

The device is lost right as it's being returned by requestDevice.
- `device.lost` resolves.
Expand All @@ -184,7 +189,7 @@ If an error is not captured, it may fire the Device's "unhandlederror" event (be

Creation of the adapter and device.

- `gpu.requestAdapter`
- `gpu.requestAdapters`
- `GPUAdapter.requestDevice`

Handled by "Fatal Errors" above.
Expand Down
36 changes: 21 additions & 15 deletions spec/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ These measures are similar to those used in WebGL.

## Fingerprinting ## {#security-fingerprint}
WebGPU defines the lowest allowed limits and capabilities of any {{GPUAdapter}}.
and encourages applications to target these standard limits. The actual result from
{{GPU/requestAdapter()}} may have higher limits, and could be subject to finger printing.
and encourages applications to target these standard limits. The actual results from
{{GPU/requestAdapters()}} may have higher limits, and could be subject to fingerprinting.


Terminology &amp; Conventions {#terminology-and-conventions}
Expand Down Expand Up @@ -496,29 +496,33 @@ partial interface WorkerNavigator {
<script type=idl>
[Exposed=(Window, DedicatedWorker)]
interface GPU {
Promise<GPUAdapter> requestAdapter(optional GPURequestAdapterOptions options = {});
Promise<sequence<GPUAdapter>> requestAdapters(optional GPURequestAdapterOptions options = {});
};
</script>

{{GPU}} has the methods defined by the following sections.

### <dfn method for=GPU>requestAdapter(options)</dfn> ### {#requestadapter}
### <dfn method for=GPU>requestAdapters(options)</dfn> ### {#requestadapter}

<div algorithm=requestAdapter>
<div algorithm=requestAdapters>
**Arguments:**
- optional {{GPURequestAdapterOptions}} |options| = {}

**Returns:** |promise|, of type Promise<{{GPUAdapter}}>.
**Returns:** |promise|, of type Promise<sequence<{{GPUAdapter}}>>.

Requests an [=adapter=] from the user agent.
The user agent chooses whether to return an adapter, and, if so,
chooses according to the provided |options|.

Returns [=a new promise=], |promise|.

- If the user agent chooses to return an adapter,
|promise| [=resolves=] with a new {{GPUAdapter}} encapsulating
a new [=adapter=].
- If the user agent chooses to return adapters, |promise| [=resolves=]
with a sequence of *at least one* {{GPUAdapter}} objects.
If a {{GPUAdapter}} represents an [=adapter=] which was previously
returned to this [=agent=], it will be returned as the same {{GPUAdapter}} object.
The order and contents of this sequence are influenced by the provided
{{GPURequestAdapterOptions}} {{GPU/requestAdapters()/options}}.

- Otherwise, |promise| [=rejects=] with an {{OperationError}}.

Issue: Figure out how to integrate the options.
Expand Down Expand Up @@ -546,14 +550,16 @@ enum GPUPowerPreference {
<dl dfn-type=dict-member dfn-for=GPURequestAdapterOptions>
: <dfn>powerPreference</dfn>
::
Optionally provides a hint indicating what class of [=adapter=] should be selected from
the system's available adapters.
Optionally provides a hint indicating what class of [=adapter=] should be preferred.

The adapters returned for the request will be ordered according to preference,
with preferred adapters appearing at the beginning of the list.

The value of this hint may influence which adapter is chosen, but it must not
influence whether an adapter is returned or not.
This hint may also influence which adapters are or are not returned for the request.

Note:
The primary utility of this hint is to influence which GPU is used in a multi-GPU system.
The primary utility of this hint is to influence which GPU is listed
first in a multi-GPU system.
For instance, some laptops have a low-power integrated GPU and a high-performance
discrete GPU.

Expand Down Expand Up @@ -600,7 +606,7 @@ enum GPUPowerPreference {
A {{GPUAdapter}} encapsulates an [=adapter=],
and describes its capabilities (extensions and limits).

To get a {{GPUAdapter}}, use {{GPU/requestAdapter()}}.
To get a {{GPUAdapter}}, use `navigator.gpu.`{{GPU/requestAdapters()}}.

<script type=idl>
interface GPUAdapter {
Expand Down