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

[WebGPU] Add lost attribute to GPUDevice

This CLs adds the lost attribute to GPUDevice. It is used to track fatal
errors in WebGPU. See https://gpuweb.github.io/gpuweb/#fatal-errors

Bug: 877147
Change-Id: I81fea6cdc300a577825d098f3c040e4969dcb0de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1827562Reviewed-by: default avatarAustin Eng <enga@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarCorentin Wallez <cwallez@chromium.org>
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/master@{#701477}
parent b8ada596
...@@ -468,6 +468,7 @@ modules_idl_files = ...@@ -468,6 +468,7 @@ modules_idl_files =
"webgpu/gpu_compute_pass_encoder.idl", "webgpu/gpu_compute_pass_encoder.idl",
"webgpu/gpu_compute_pipeline.idl", "webgpu/gpu_compute_pipeline.idl",
"webgpu/gpu_device.idl", "webgpu/gpu_device.idl",
"webgpu/gpu_device_lost_info.idl",
"webgpu/gpu_fence.idl", "webgpu/gpu_fence.idl",
"webgpu/gpu_out_of_memory_error.idl", "webgpu/gpu_out_of_memory_error.idl",
"webgpu/gpu_pipeline_layout.idl", "webgpu/gpu_pipeline_layout.idl",
......
...@@ -35,6 +35,8 @@ blink_modules_sources("webgpu") { ...@@ -35,6 +35,8 @@ blink_modules_sources("webgpu") {
"gpu_compute_pipeline.h", "gpu_compute_pipeline.h",
"gpu_device.cc", "gpu_device.cc",
"gpu_device.h", "gpu_device.h",
"gpu_device_lost_info.cc",
"gpu_device_lost_info.h",
"gpu_fence.cc", "gpu_fence.cc",
"gpu_fence.h", "gpu_fence.h",
"gpu_out_of_memory_error.cc", "gpu_out_of_memory_error.cc",
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "third_party/blink/renderer/modules/webgpu/gpu_command_encoder.h" #include "third_party/blink/renderer/modules/webgpu/gpu_command_encoder.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_compute_pipeline.h" #include "third_party/blink/renderer/modules/webgpu/gpu_compute_pipeline.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_device_descriptor.h" #include "third_party/blink/renderer/modules/webgpu/gpu_device_descriptor.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_device_lost_info.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_pipeline_layout.h" #include "third_party/blink/renderer/modules/webgpu/gpu_pipeline_layout.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_queue.h" #include "third_party/blink/renderer/modules/webgpu/gpu_queue.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_render_bundle_encoder.h" #include "third_party/blink/renderer/modules/webgpu/gpu_render_bundle_encoder.h"
...@@ -50,6 +51,9 @@ GPUDevice::GPUDevice(ExecutionContext* execution_context, ...@@ -50,6 +51,9 @@ GPUDevice::GPUDevice(ExecutionContext* execution_context,
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()))),
lost_property_(MakeGarbageCollected<LostProperty>(execution_context,
this,
LostProperty::kLost)),
error_callback_( error_callback_(
BindRepeatingDawnCallback(&GPUDevice::OnUncapturedError, BindRepeatingDawnCallback(&GPUDevice::OnUncapturedError,
WrapWeakPersistent(this), WrapWeakPersistent(this),
...@@ -78,6 +82,13 @@ void GPUDevice::OnUncapturedError(ExecutionContext* execution_context, ...@@ -78,6 +82,13 @@ void GPUDevice::OnUncapturedError(ExecutionContext* execution_context,
execution_context->AddConsoleMessage(console_message); execution_context->AddConsoleMessage(console_message);
} }
// TODO: Use device lost callback instead of uncaptured error callback.
if (errorType == DAWN_ERROR_TYPE_DEVICE_LOST &&
lost_property_->GetState() == ScriptPromisePropertyBase::kPending) {
GPUDeviceLostInfo* device_lost_info = GPUDeviceLostInfo::Create(message);
lost_property_->Resolve(device_lost_info);
}
GPUUncapturedErrorEventInit* init = GPUUncapturedErrorEventInit::Create(); GPUUncapturedErrorEventInit* init = GPUUncapturedErrorEventInit::Create();
if (errorType == DAWN_ERROR_TYPE_VALIDATION) { if (errorType == DAWN_ERROR_TYPE_VALIDATION) {
GPUValidationError* error = GPUValidationError::Create(message); GPUValidationError* error = GPUValidationError::Create(message);
...@@ -99,6 +110,10 @@ GPUAdapter* GPUDevice::adapter() const { ...@@ -99,6 +110,10 @@ GPUAdapter* GPUDevice::adapter() const {
return adapter_; return adapter_;
} }
ScriptPromise GPUDevice::lost(ScriptState* script_state) {
return lost_property_->Promise(script_state->World());
}
GPUBuffer* GPUDevice::createBuffer(const GPUBufferDescriptor* descriptor) { GPUBuffer* GPUDevice::createBuffer(const GPUBufferDescriptor* descriptor) {
return GPUBuffer::Create(this, descriptor); return GPUBuffer::Create(this, descriptor);
} }
...@@ -276,6 +291,7 @@ const AtomicString& GPUDevice::InterfaceName() const { ...@@ -276,6 +291,7 @@ const AtomicString& GPUDevice::InterfaceName() const {
void GPUDevice::Trace(blink::Visitor* visitor) { void GPUDevice::Trace(blink::Visitor* visitor) {
visitor->Trace(adapter_); visitor->Trace(adapter_);
visitor->Trace(queue_); visitor->Trace(queue_);
visitor->Trace(lost_property_);
ContextClient::Trace(visitor); ContextClient::Trace(visitor);
EventTargetWithInlineData::Trace(visitor); EventTargetWithInlineData::Trace(visitor);
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#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/bindings/core/v8/script_promise_property.h"
#include "third_party/blink/renderer/core/dom/events/event_target.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/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"
...@@ -28,6 +29,7 @@ class GPUBindGroupLayoutDescriptor; ...@@ -28,6 +29,7 @@ class GPUBindGroupLayoutDescriptor;
class GPUComputePipeline; class GPUComputePipeline;
class GPUComputePipelineDescriptor; class GPUComputePipelineDescriptor;
class GPUDeviceDescriptor; class GPUDeviceDescriptor;
class GPUDeviceLostInfo;
class GPUPipelineLayout; class GPUPipelineLayout;
class GPUPipelineLayoutDescriptor; class GPUPipelineLayoutDescriptor;
class GPUQueue; class GPUQueue;
...@@ -66,6 +68,7 @@ class GPUDevice final : public EventTargetWithInlineData, ...@@ -66,6 +68,7 @@ class GPUDevice final : public EventTargetWithInlineData,
// gpu_device.idl // gpu_device.idl
GPUAdapter* adapter() const; GPUAdapter* adapter() const;
ScriptPromise lost(ScriptState* script_state);
GPUBuffer* createBuffer(const GPUBufferDescriptor* descriptor); GPUBuffer* createBuffer(const GPUBufferDescriptor* descriptor);
HeapVector<ScriptValue> createBufferMapped( HeapVector<ScriptValue> createBufferMapped(
...@@ -110,6 +113,10 @@ class GPUDevice final : public EventTargetWithInlineData, ...@@ -110,6 +113,10 @@ class GPUDevice final : public EventTargetWithInlineData,
ExecutionContext* GetExecutionContext() const override; ExecutionContext* GetExecutionContext() const override;
private: private:
using LostProperty = ScriptPromiseProperty<Member<GPUDevice>,
Member<GPUDeviceLostInfo>,
ToV8UndefinedGenerator>;
void OnUncapturedError(ExecutionContext* execution_context, void OnUncapturedError(ExecutionContext* execution_context,
DawnErrorType errorType, DawnErrorType errorType,
const char* message); const char* message);
...@@ -120,6 +127,7 @@ class GPUDevice final : public EventTargetWithInlineData, ...@@ -120,6 +127,7 @@ class GPUDevice final : public EventTargetWithInlineData,
Member<GPUAdapter> adapter_; Member<GPUAdapter> adapter_;
Member<GPUQueue> queue_; Member<GPUQueue> queue_;
Member<LostProperty> lost_property_;
std::unique_ptr< std::unique_ptr<
DawnCallback<base::RepeatingCallback<void(DawnErrorType, const char*)>>> DawnCallback<base::RepeatingCallback<void(DawnErrorType, const char*)>>>
error_callback_; error_callback_;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
RuntimeEnabled=WebGPU RuntimeEnabled=WebGPU
] interface GPUDevice : EventTarget { ] interface GPUDevice : EventTarget {
readonly attribute GPUAdapter adapter; readonly attribute GPUAdapter adapter;
[CallWith=ScriptState] readonly attribute Promise<GPUDeviceLostInfo> lost;
GPUBuffer createBuffer(GPUBufferDescriptor descriptor); GPUBuffer createBuffer(GPUBufferDescriptor descriptor);
[CallWith=ScriptState, RaisesException] GPUMappedBuffer createBufferMapped(GPUBufferDescriptor descriptor); [CallWith=ScriptState, RaisesException] GPUMappedBuffer createBufferMapped(GPUBufferDescriptor descriptor);
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/webgpu/gpu_device_lost_info.h"
namespace blink {
// static
GPUDeviceLostInfo* GPUDeviceLostInfo::Create(const String& message) {
return MakeGarbageCollected<GPUDeviceLostInfo>(message);
}
GPUDeviceLostInfo::GPUDeviceLostInfo(const String& message) {
message_ = message;
}
const String& GPUDeviceLostInfo::message() const {
return message_;
}
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_DEVICE_LOST_INFO_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_DEVICE_LOST_INFO_H_
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class GPUDeviceLostInfo : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static GPUDeviceLostInfo* Create(const String& message);
GPUDeviceLostInfo(const String& message);
// gpu_device_lost_info.idl
const String& message() const;
private:
String message_;
DISALLOW_COPY_AND_ASSIGN(GPUDeviceLostInfo);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_DEVICE_LOST_INFO_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://gpuweb.github.io/gpuweb/
[
RuntimeEnabled=WebGPU
] interface GPUDeviceLostInfo {
readonly attribute DOMString message;
};
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
P(ScriptPromise, kClosed##__VA_ARGS__) \ P(ScriptPromise, kClosed##__VA_ARGS__) \
P(ScriptPromise, kFinished##__VA_ARGS__) \ P(ScriptPromise, kFinished##__VA_ARGS__) \
P(ScriptPromise, kLoaded##__VA_ARGS__) \ P(ScriptPromise, kLoaded##__VA_ARGS__) \
P(ScriptPromise, kLost##__VA_ARGS__) \
P(ScriptPromise, kReleased##__VA_ARGS__) \ P(ScriptPromise, kReleased##__VA_ARGS__) \
P(ScriptPromise, kResponseReady##__VA_ARGS__) \ P(ScriptPromise, kResponseReady##__VA_ARGS__) \
P(ScriptPromise, kUserChoice##__VA_ARGS__) \ P(ScriptPromise, kUserChoice##__VA_ARGS__) \
......
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