Commit 2ab82e58 authored by Austin Eng's avatar Austin Eng Committed by Commit Bot

WebGPU: Implement GPUDevice.push/popErrorScope

Bug: dawn:153
Change-Id: Icf184299866a54b170a1ef3558bcc4e2bf1fcc10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790384
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: default avatarCorentin Wallez <cwallez@chromium.org>
Reviewed-by: default avatarKai Ninomiya <kainino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695423}
parent 389f9fa6
...@@ -681,6 +681,21 @@ DawnTextureAspect AsDawnEnum<DawnTextureAspect>( ...@@ -681,6 +681,21 @@ DawnTextureAspect AsDawnEnum<DawnTextureAspect>(
return DAWN_TEXTURE_ASPECT_FORCE32; return DAWN_TEXTURE_ASPECT_FORCE32;
} }
template <>
DawnErrorFilter AsDawnEnum<DawnErrorFilter>(const WTF::String& webgpu_enum) {
if (webgpu_enum == "none") {
return DAWN_ERROR_FILTER_NONE;
}
if (webgpu_enum == "out-of-memory") {
return DAWN_ERROR_FILTER_OUT_OF_MEMORY;
}
if (webgpu_enum == "validation") {
return DAWN_ERROR_FILTER_VALIDATION;
}
NOTREACHED();
return DAWN_ERROR_FILTER_FORCE32;
}
DawnColor AsDawnType(const GPUColor* webgpu_color) { DawnColor AsDawnType(const GPUColor* webgpu_color) {
DCHECK(webgpu_color); DCHECK(webgpu_color);
......
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
#include "gpu/command_buffer/client/webgpu_interface.h" #include "gpu/command_buffer/client/webgpu_interface.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/modules/event_target_modules.h" #include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/webgpu/dawn_conversions.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_adapter.h" #include "third_party/blink/renderer/modules/webgpu/gpu_adapter.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_bind_group.h" #include "third_party/blink/renderer/modules/webgpu/gpu_bind_group.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_bind_group_layout.h" #include "third_party/blink/renderer/modules/webgpu/gpu_bind_group_layout.h"
...@@ -209,6 +211,60 @@ GPUQueue* GPUDevice::getQueue() { ...@@ -209,6 +211,60 @@ GPUQueue* GPUDevice::getQueue() {
return queue_; return queue_;
} }
void GPUDevice::pushErrorScope(const WTF::String& filter) {
GetProcs().devicePushErrorScope(GetHandle(),
AsDawnEnum<DawnErrorFilter>(filter));
}
ScriptPromise GPUDevice::popErrorScope(ScriptState* script_state,
ExceptionState& exception_state) {
ScriptPromiseResolver* resolver =
MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise promise = resolver->Promise();
auto* callback =
BindDawnCallback(&GPUDevice::OnPopErrorScopeCallback,
WrapPersistent(this), WrapPersistent(resolver));
if (!GetProcs().devicePopErrorScope(GetHandle(), callback->UnboundCallback(),
callback->AsUserdata())) {
exception_state.ThrowDOMException(DOMExceptionCode::kOperationError,
"No error scopes to pop.");
delete callback;
}
// WebGPU guarantees callbacks complete in finite time. Flush now so that
// commands reach the GPU process. TODO(enga): This should happen at the end
// of the task.
GetInterface()->FlushCommands();
return promise;
}
void GPUDevice::OnPopErrorScopeCallback(ScriptPromiseResolver* resolver,
DawnErrorType type,
const char* message) {
ScriptState* script_state = resolver->GetScriptState();
switch (type) {
case DAWN_ERROR_TYPE_NO_ERROR:
resolver->Resolve(ScriptValue::CreateNull(script_state));
break;
case DAWN_ERROR_TYPE_OUT_OF_MEMORY:
resolver->Resolve(GPUOutOfMemoryError::Create());
break;
case DAWN_ERROR_TYPE_VALIDATION:
resolver->Resolve(GPUValidationError::Create(message));
break;
case DAWN_ERROR_TYPE_UNKNOWN:
case DAWN_ERROR_TYPE_DEVICE_LOST:
resolver->Reject(
MakeGarbageCollected<DOMException>(DOMExceptionCode::kAbortError));
break;
default:
NOTREACHED();
}
}
ExecutionContext* GPUDevice::GetExecutionContext() const { ExecutionContext* GPUDevice::GetExecutionContext() const {
return ContextClient::GetExecutionContext(); return ContextClient::GetExecutionContext();
} }
......
...@@ -41,6 +41,7 @@ class GPUShaderModule; ...@@ -41,6 +41,7 @@ class GPUShaderModule;
class GPUShaderModuleDescriptor; class GPUShaderModuleDescriptor;
class GPUTexture; class GPUTexture;
class GPUTextureDescriptor; class GPUTextureDescriptor;
class ScriptPromiseResolver;
class ScriptState; class ScriptState;
class GPUDevice final : public EventTargetWithInlineData, class GPUDevice final : public EventTargetWithInlineData,
...@@ -98,6 +99,10 @@ class GPUDevice final : public EventTargetWithInlineData, ...@@ -98,6 +99,10 @@ class GPUDevice final : public EventTargetWithInlineData,
GPUQueue* getQueue(); GPUQueue* getQueue();
void pushErrorScope(const WTF::String& filter);
ScriptPromise popErrorScope(ScriptState* script_state,
ExceptionState& exception_state);
DEFINE_ATTRIBUTE_EVENT_LISTENER(uncapturederror, kUncapturederror) DEFINE_ATTRIBUTE_EVENT_LISTENER(uncapturederror, kUncapturederror)
// EventTarget overrides. // EventTarget overrides.
...@@ -109,6 +114,10 @@ class GPUDevice final : public EventTargetWithInlineData, ...@@ -109,6 +114,10 @@ class GPUDevice final : public EventTargetWithInlineData,
DawnErrorType errorType, DawnErrorType errorType,
const char* message); const char* message);
void OnPopErrorScopeCallback(ScriptPromiseResolver* resolver,
DawnErrorType type,
const char* message);
Member<GPUAdapter> adapter_; Member<GPUAdapter> adapter_;
Member<GPUQueue> queue_; Member<GPUQueue> queue_;
std::unique_ptr< std::unique_ptr<
......
...@@ -27,8 +27,17 @@ ...@@ -27,8 +27,17 @@
GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor); GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor);
GPUQueue getQueue(); GPUQueue getQueue();
void pushErrorScope(GPUErrorFilter filter);
[CallWith=ScriptState, RaisesException] Promise<GPUError?> popErrorScope();
attribute EventHandler onuncapturederror; attribute EventHandler onuncapturederror;
}; };
enum GPUErrorFilter {
"none",
"out-of-memory",
"validation"
};
typedef sequence<any> GPUMappedBuffer; // [GPUBuffer, ArrayBuffer] typedef sequence<any> GPUMappedBuffer; // [GPUBuffer, ArrayBuffer]
typedef (GPUOutOfMemoryError or GPUValidationError) GPUError; typedef (GPUOutOfMemoryError or GPUValidationError) GPUError;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment