Commit a1caeb05 authored by François Beaufort's avatar François Beaufort Committed by Commit Bot

[WebGPU] Add GPUDevice onuncapturederror event handler.

This CL makes GPUDevice an EventTarget. When an uncaptured error is
raised in Dawn, the "uncapturederror" error is fired in GPUDevice.

Change-Id: Ib0082e080667448e309d9879ea22de7ac1706fad
Bug: 877147
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1787504
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: default avatarCorentin Wallez <cwallez@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694216}
parent 2cfd5b6a
......@@ -287,6 +287,7 @@
"transitionrun",
"transitionstart",
"typechange",
"uncapturederror",
"unhandledrejection",
"unload",
"unmute",
......
......@@ -16,6 +16,7 @@
"CookieStore",
"MediaKeySession",
"FileWriter",
"GPUDevice",
"HID",
"HIDDevice",
"IdleDetector",
......
......@@ -12,8 +12,6 @@ DawnObjectBase::DawnObjectBase(
scoped_refptr<DawnControlClientHolder> dawn_control_client)
: dawn_control_client_(std::move(dawn_control_client)) {}
DawnObjectBase::~DawnObjectBase() = default;
const scoped_refptr<DawnControlClientHolder>&
DawnObjectBase::GetDawnControlClient() const {
return dawn_control_client_;
......@@ -34,6 +32,8 @@ const DawnProcTable& DawnObjectBase::GetProcs() const {
DawnObjectImpl::DawnObjectImpl(GPUDevice* device)
: DawnObjectBase(device->GetDawnControlClient()), device_(device) {}
DawnObjectImpl::~DawnObjectImpl() = default;
void DawnObjectImpl::Trace(blink::Visitor* visitor) {
visitor->Trace(device_);
ScriptWrappable::Trace(visitor);
......
......@@ -28,10 +28,9 @@ class Visitor;
// The DawnControlClientHolder is used to hold the WebGPUInterface and keep
// track of whether or not the client has been destroyed. If the client is
// destroyed, we should not call any Dawn functions.
class DawnObjectBase : public ScriptWrappable {
class DawnObjectBase {
public:
DawnObjectBase(scoped_refptr<DawnControlClientHolder> dawn_control_client);
~DawnObjectBase() override;
const scoped_refptr<DawnControlClientHolder>& GetDawnControlClient() const;
bool IsDawnControlClientDestroyed() const;
......@@ -42,9 +41,10 @@ class DawnObjectBase : public ScriptWrappable {
scoped_refptr<DawnControlClientHolder> dawn_control_client_;
};
class DawnObjectImpl : public DawnObjectBase {
class DawnObjectImpl : public ScriptWrappable, public DawnObjectBase {
public:
DawnObjectImpl(GPUDevice* device);
~DawnObjectImpl() override;
void Trace(blink::Visitor* visitor) override;
......
......@@ -16,7 +16,7 @@ namespace blink {
class GPUDeviceDescriptor;
class GPUAdapter final : public DawnObjectBase {
class GPUAdapter final : public ScriptWrappable, public DawnObjectBase {
DEFINE_WRAPPERTYPEINFO();
public:
......
......@@ -7,8 +7,8 @@
#include "gpu/command_buffer/client/webgpu_interface.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/core/execution_context/execution_context.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/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_layout.h"
......@@ -23,6 +23,8 @@
#include "third_party/blink/renderer/modules/webgpu/gpu_sampler.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_shader_module.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_texture.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_uncaptured_error_event.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_uncaptured_error_event_init.h"
namespace blink {
......@@ -41,7 +43,8 @@ GPUDevice::GPUDevice(ExecutionContext* execution_context,
scoped_refptr<DawnControlClientHolder> dawn_control_client,
GPUAdapter* adapter,
const GPUDeviceDescriptor* descriptor)
: DawnObject(dawn_control_client,
: ContextClient(execution_context),
DawnObject(dawn_control_client,
dawn_control_client->GetInterface()->GetDefaultDevice()),
adapter_(adapter),
queue_(GPUQueue::Create(this, GetProcs().deviceCreateQueue(GetHandle()))),
......@@ -72,6 +75,22 @@ void GPUDevice::OnUncapturedError(ExecutionContext* execution_context,
mojom::ConsoleMessageLevel::kWarning, message);
execution_context->AddConsoleMessage(console_message);
}
GPUUncapturedErrorEventInit* init = GPUUncapturedErrorEventInit::Create();
if (errorType == DAWN_ERROR_TYPE_VALIDATION) {
GPUValidationError* error = GPUValidationError::Create(message);
init->setError(
GPUOutOfMemoryErrorOrGPUValidationError::FromGPUValidationError(error));
} else if (errorType == DAWN_ERROR_TYPE_OUT_OF_MEMORY) {
GPUOutOfMemoryError* error = GPUOutOfMemoryError::Create();
init->setError(
GPUOutOfMemoryErrorOrGPUValidationError::FromGPUOutOfMemoryError(
error));
} else {
return;
}
this->DispatchEvent(*GPUUncapturedErrorEvent::Create(
event_type_names::kUncapturederror, init));
}
GPUAdapter* GPUDevice::adapter() const {
......@@ -190,10 +209,19 @@ GPUQueue* GPUDevice::getQueue() {
return queue_;
}
ExecutionContext* GPUDevice::GetExecutionContext() const {
return ContextClient::GetExecutionContext();
}
const AtomicString& GPUDevice::InterfaceName() const {
return event_target_names::kGPUDevice;
}
void GPUDevice::Trace(blink::Visitor* visitor) {
visitor->Trace(adapter_);
visitor->Trace(queue_);
DawnObject<DawnDevice>::Trace(visitor);
ContextClient::Trace(visitor);
EventTargetWithInlineData::Trace(visitor);
}
} // namespace blink
......@@ -7,6 +7,8 @@
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/core/dom/events/event_target.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/modules/webgpu/dawn_callback.h"
#include "third_party/blink/renderer/modules/webgpu/dawn_object.h"
......@@ -41,7 +43,10 @@ class GPUTexture;
class GPUTextureDescriptor;
class ScriptState;
class GPUDevice final : public DawnObject<DawnDevice> {
class GPUDevice final : public EventTargetWithInlineData,
public ContextClient,
public DawnObject<DawnDevice> {
USING_GARBAGE_COLLECTED_MIXIN(GPUDevice);
DEFINE_WRAPPERTYPEINFO();
public:
......@@ -93,6 +98,12 @@ class GPUDevice final : public DawnObject<DawnDevice> {
GPUQueue* getQueue();
DEFINE_ATTRIBUTE_EVENT_LISTENER(uncapturederror, kUncapturederror)
// EventTarget overrides.
const AtomicString& InterfaceName() const override;
ExecutionContext* GetExecutionContext() const override;
private:
void OnUncapturedError(ExecutionContext* execution_context,
DawnErrorType errorType,
......
......@@ -6,7 +6,7 @@
[
RuntimeEnabled=WebGPU
] interface GPUDevice {
] interface GPUDevice : EventTarget {
readonly attribute GPUAdapter adapter;
GPUBuffer createBuffer(GPUBufferDescriptor descriptor);
......@@ -26,6 +26,8 @@
GPUCommandEncoder createCommandEncoder(optional GPUCommandEncoderDescriptor descriptor);
GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor);
GPUQueue getQueue();
attribute EventHandler onuncapturederror;
};
typedef sequence<any> GPUMappedBuffer; // [GPUBuffer, ArrayBuffer]
......
......@@ -19,7 +19,8 @@ class GPUDevice;
class GPUSwapChainDescriptor;
class GPUTexture;
class GPUSwapChain : public DawnObjectBase,
class GPUSwapChain : public ScriptWrappable,
public DawnObjectBase,
public WebGPUSwapBufferProvider::Client {
DEFINE_WRAPPERTYPEINFO();
......
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