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 @@ ...@@ -287,6 +287,7 @@
"transitionrun", "transitionrun",
"transitionstart", "transitionstart",
"typechange", "typechange",
"uncapturederror",
"unhandledrejection", "unhandledrejection",
"unload", "unload",
"unmute", "unmute",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"CookieStore", "CookieStore",
"MediaKeySession", "MediaKeySession",
"FileWriter", "FileWriter",
"GPUDevice",
"HID", "HID",
"HIDDevice", "HIDDevice",
"IdleDetector", "IdleDetector",
......
...@@ -12,8 +12,6 @@ DawnObjectBase::DawnObjectBase( ...@@ -12,8 +12,6 @@ DawnObjectBase::DawnObjectBase(
scoped_refptr<DawnControlClientHolder> dawn_control_client) scoped_refptr<DawnControlClientHolder> dawn_control_client)
: dawn_control_client_(std::move(dawn_control_client)) {} : dawn_control_client_(std::move(dawn_control_client)) {}
DawnObjectBase::~DawnObjectBase() = default;
const scoped_refptr<DawnControlClientHolder>& const scoped_refptr<DawnControlClientHolder>&
DawnObjectBase::GetDawnControlClient() const { DawnObjectBase::GetDawnControlClient() const {
return dawn_control_client_; return dawn_control_client_;
...@@ -34,6 +32,8 @@ const DawnProcTable& DawnObjectBase::GetProcs() const { ...@@ -34,6 +32,8 @@ const DawnProcTable& DawnObjectBase::GetProcs() const {
DawnObjectImpl::DawnObjectImpl(GPUDevice* device) DawnObjectImpl::DawnObjectImpl(GPUDevice* device)
: DawnObjectBase(device->GetDawnControlClient()), device_(device) {} : DawnObjectBase(device->GetDawnControlClient()), device_(device) {}
DawnObjectImpl::~DawnObjectImpl() = default;
void DawnObjectImpl::Trace(blink::Visitor* visitor) { void DawnObjectImpl::Trace(blink::Visitor* visitor) {
visitor->Trace(device_); visitor->Trace(device_);
ScriptWrappable::Trace(visitor); ScriptWrappable::Trace(visitor);
......
...@@ -28,10 +28,9 @@ class Visitor; ...@@ -28,10 +28,9 @@ class Visitor;
// The DawnControlClientHolder is used to hold the WebGPUInterface and keep // The DawnControlClientHolder is used to hold the WebGPUInterface and keep
// track of whether or not the client has been destroyed. If the client is // track of whether or not the client has been destroyed. If the client is
// destroyed, we should not call any Dawn functions. // destroyed, we should not call any Dawn functions.
class DawnObjectBase : public ScriptWrappable { class DawnObjectBase {
public: public:
DawnObjectBase(scoped_refptr<DawnControlClientHolder> dawn_control_client); DawnObjectBase(scoped_refptr<DawnControlClientHolder> dawn_control_client);
~DawnObjectBase() override;
const scoped_refptr<DawnControlClientHolder>& GetDawnControlClient() const; const scoped_refptr<DawnControlClientHolder>& GetDawnControlClient() const;
bool IsDawnControlClientDestroyed() const; bool IsDawnControlClientDestroyed() const;
...@@ -42,9 +41,10 @@ class DawnObjectBase : public ScriptWrappable { ...@@ -42,9 +41,10 @@ class DawnObjectBase : public ScriptWrappable {
scoped_refptr<DawnControlClientHolder> dawn_control_client_; scoped_refptr<DawnControlClientHolder> dawn_control_client_;
}; };
class DawnObjectImpl : public DawnObjectBase { class DawnObjectImpl : public ScriptWrappable, public DawnObjectBase {
public: public:
DawnObjectImpl(GPUDevice* device); DawnObjectImpl(GPUDevice* device);
~DawnObjectImpl() override;
void Trace(blink::Visitor* visitor) override; void Trace(blink::Visitor* visitor) override;
......
...@@ -16,7 +16,7 @@ namespace blink { ...@@ -16,7 +16,7 @@ namespace blink {
class GPUDeviceDescriptor; class GPUDeviceDescriptor;
class GPUAdapter final : public DawnObjectBase { class GPUAdapter final : public ScriptWrappable, public DawnObjectBase {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#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/execution_context/execution_context.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/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"
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "third_party/blink/renderer/modules/webgpu/gpu_sampler.h" #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_shader_module.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_texture.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 { namespace blink {
...@@ -41,7 +43,8 @@ GPUDevice::GPUDevice(ExecutionContext* execution_context, ...@@ -41,7 +43,8 @@ GPUDevice::GPUDevice(ExecutionContext* execution_context,
scoped_refptr<DawnControlClientHolder> dawn_control_client, scoped_refptr<DawnControlClientHolder> dawn_control_client,
GPUAdapter* adapter, GPUAdapter* adapter,
const GPUDeviceDescriptor* descriptor) const GPUDeviceDescriptor* descriptor)
: DawnObject(dawn_control_client, : ContextClient(execution_context),
DawnObject(dawn_control_client,
dawn_control_client->GetInterface()->GetDefaultDevice()), dawn_control_client->GetInterface()->GetDefaultDevice()),
adapter_(adapter), adapter_(adapter),
queue_(GPUQueue::Create(this, GetProcs().deviceCreateQueue(GetHandle()))), queue_(GPUQueue::Create(this, GetProcs().deviceCreateQueue(GetHandle()))),
...@@ -72,6 +75,22 @@ void GPUDevice::OnUncapturedError(ExecutionContext* execution_context, ...@@ -72,6 +75,22 @@ void GPUDevice::OnUncapturedError(ExecutionContext* execution_context,
mojom::ConsoleMessageLevel::kWarning, message); mojom::ConsoleMessageLevel::kWarning, message);
execution_context->AddConsoleMessage(console_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 { GPUAdapter* GPUDevice::adapter() const {
...@@ -190,10 +209,19 @@ GPUQueue* GPUDevice::getQueue() { ...@@ -190,10 +209,19 @@ GPUQueue* GPUDevice::getQueue() {
return queue_; 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) { void GPUDevice::Trace(blink::Visitor* visitor) {
visitor->Trace(adapter_); visitor->Trace(adapter_);
visitor->Trace(queue_); visitor->Trace(queue_);
DawnObject<DawnDevice>::Trace(visitor); ContextClient::Trace(visitor);
EventTargetWithInlineData::Trace(visitor);
} }
} // namespace blink } // namespace blink
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.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_callback.h"
#include "third_party/blink/renderer/modules/webgpu/dawn_object.h" #include "third_party/blink/renderer/modules/webgpu/dawn_object.h"
...@@ -41,7 +43,10 @@ class GPUTexture; ...@@ -41,7 +43,10 @@ class GPUTexture;
class GPUTextureDescriptor; class GPUTextureDescriptor;
class ScriptState; 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(); DEFINE_WRAPPERTYPEINFO();
public: public:
...@@ -93,6 +98,12 @@ class GPUDevice final : public DawnObject<DawnDevice> { ...@@ -93,6 +98,12 @@ class GPUDevice final : public DawnObject<DawnDevice> {
GPUQueue* getQueue(); GPUQueue* getQueue();
DEFINE_ATTRIBUTE_EVENT_LISTENER(uncapturederror, kUncapturederror)
// EventTarget overrides.
const AtomicString& InterfaceName() const override;
ExecutionContext* GetExecutionContext() const override;
private: private:
void OnUncapturedError(ExecutionContext* execution_context, void OnUncapturedError(ExecutionContext* execution_context,
DawnErrorType errorType, DawnErrorType errorType,
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
[ [
RuntimeEnabled=WebGPU RuntimeEnabled=WebGPU
] interface GPUDevice { ] interface GPUDevice : EventTarget {
readonly attribute GPUAdapter adapter; readonly attribute GPUAdapter adapter;
GPUBuffer createBuffer(GPUBufferDescriptor descriptor); GPUBuffer createBuffer(GPUBufferDescriptor descriptor);
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
GPUCommandEncoder createCommandEncoder(optional GPUCommandEncoderDescriptor descriptor); GPUCommandEncoder createCommandEncoder(optional GPUCommandEncoderDescriptor descriptor);
GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor); GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor);
GPUQueue getQueue(); GPUQueue getQueue();
attribute EventHandler onuncapturederror;
}; };
typedef sequence<any> GPUMappedBuffer; // [GPUBuffer, ArrayBuffer] typedef sequence<any> GPUMappedBuffer; // [GPUBuffer, ArrayBuffer]
......
...@@ -19,7 +19,8 @@ class GPUDevice; ...@@ -19,7 +19,8 @@ class GPUDevice;
class GPUSwapChainDescriptor; class GPUSwapChainDescriptor;
class GPUTexture; class GPUTexture;
class GPUSwapChain : public DawnObjectBase, class GPUSwapChain : public ScriptWrappable,
public DawnObjectBase,
public WebGPUSwapBufferProvider::Client { public WebGPUSwapBufferProvider::Client {
DEFINE_WRAPPERTYPEINFO(); 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