Skip to content

Commit

Permalink
Document that error scopes are thread-local (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x authored Dec 4, 2024
1 parent d22ced3 commit b74f922
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions doc/articles/Errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ These errors include:
- Enum values which are require features not enabled on the device (a [content-timeline](https://www.w3.org/TR/webgpu/#content-timeline) error in JavaScript), for example compressed texture formats.
- Other content-timeline errors where specified.

### Error Scopes {#ErrorScopes}

Error scopes are used via @ref wgpuDevicePushErrorScope, @ref wgpuDevicePopErrorScope, and @ref WGPUDeviceDescriptor::uncapturedErrorCallbackInfo. These behave the same as in the JavaScript API, except for considerations around multi-threading (which JavaScript doesn't have at the time of this writing):

- The error scope stack state is **thread-local**: each thread has a separate stack, which is initially empty. The error scope that captures an error depends on which thread made the API call that generated the error.
- The UncapturedError callback receives uncaptured errors from all threads.

## Callback Error {#CallbackError}

These behave similarly to the Promise-returning JavaScript APIs. Instead of there being two callbacks like in JavaScript (one for resolve and one for reject), there is a single callback which receives a status code, and depending on the status, _either_ a valid result with an empty message string (`{NULL, 0}`), _or_ an invalid result with a non-empty message string.
Expand Down
11 changes: 11 additions & 0 deletions webgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3707,6 +3707,9 @@ typedef struct WGPUDeviceDescriptor {
*/
WGPUDeviceLostCallbackInfo deviceLostCallbackInfo;
/**
* Called when there is an uncaptured error on this device, from any thread.
* See @ref ErrorScopes.
*
* The `INIT` macro sets this to @ref WGPU_UNCAPTURED_ERROR_CALLBACK_INFO_INIT.
*/
WGPUUncapturedErrorCallbackInfo uncapturedErrorCallbackInfo;
Expand Down Expand Up @@ -5571,7 +5574,15 @@ WGPU_EXPORT WGPUStatus wgpuDeviceGetLimits(WGPUDevice device, WGPULimits * limit
WGPU_EXPORT WGPUFuture wgpuDeviceGetLostFuture(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE;
WGPU_EXPORT WGPUQueue wgpuDeviceGetQueue(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE;
WGPU_EXPORT WGPUBool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeatureName feature) WGPU_FUNCTION_ATTRIBUTE;
/**
* Pops an error scope to the current thread's error scope stack,
* asynchronously returning the result. See @ref ErrorScopes.
*/
WGPU_EXPORT WGPUFuture wgpuDevicePopErrorScope(WGPUDevice device, WGPUPopErrorScopeCallbackInfo callbackInfo) WGPU_FUNCTION_ATTRIBUTE;
/**
* Pushes an error scope to the current thread's error scope stack.
* See @ref ErrorScopes.
*/
WGPU_EXPORT void wgpuDevicePushErrorScope(WGPUDevice device, WGPUErrorFilter filter) WGPU_FUNCTION_ATTRIBUTE;
WGPU_EXPORT void wgpuDeviceSetLabel(WGPUDevice device, WGPUStringView label) WGPU_FUNCTION_ATTRIBUTE;
WGPU_EXPORT void wgpuDeviceAddRef(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE;
Expand Down
9 changes: 6 additions & 3 deletions webgpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,8 @@ structs:
type: callback.device_lost
- name: uncaptured_error_callback_info
doc: |
TODO
Called when there is an uncaptured error on this device, from any thread.
See @ref ErrorScopes.
type: callback.uncaptured_error
- name: extent_3D
doc: |
Expand Down Expand Up @@ -4144,15 +4145,17 @@ objects:
passed_with_ownership: true
- name: push_error_scope
doc: |
TODO
Pushes an error scope to the current thread's error scope stack.
See @ref ErrorScopes.
args:
- name: filter
doc: |
TODO
type: enum.error_filter
- name: pop_error_scope
doc: |
TODO
Pops an error scope to the current thread's error scope stack,
asynchronously returning the result. See @ref ErrorScopes.
callback: callback.pop_error_scope
- name: set_label
doc: |
Expand Down

0 comments on commit b74f922

Please sign in to comment.