Commit 721b9e44 authored by Kai Ninomiya's avatar Kai Ninomiya Committed by Commit Bot

Add GPUDevice::AddConsoleWarning

Allows deprecation warnings during the transition period for breaking
WebGPU API changes.

Bug: 1069302
Change-Id: Ic9a34b5edbd08dad0be5401d796a4ef3e96ecc06
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2143374Reviewed-by: default avatarCorentin Wallez <cwallez@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757915}
parent a02c92f5
......@@ -46,10 +46,8 @@ GPUDevice::GPUDevice(ExecutionContext* execution_context,
this,
GetProcs().deviceCreateQueue(GetHandle()))),
lost_property_(MakeGarbageCollected<LostProperty>(execution_context)),
error_callback_(
BindRepeatingDawnCallback(&GPUDevice::OnUncapturedError,
WrapWeakPersistent(this),
WrapWeakPersistent(execution_context))),
error_callback_(BindRepeatingDawnCallback(&GPUDevice::OnUncapturedError,
WrapWeakPersistent(this))),
client_id_(client_id) {
DCHECK(dawn_control_client->GetInterface()->GetDevice(client_id));
GetProcs().deviceSetUncapturedErrorCallback(
......@@ -70,17 +68,31 @@ uint64_t GPUDevice::GetClientID() const {
return client_id_;
}
void GPUDevice::OnUncapturedError(ExecutionContext* execution_context,
WGPUErrorType errorType,
const char* message) {
if (execution_context) {
DCHECK_NE(errorType, WGPUErrorType_NoError);
LOG(ERROR) << "GPUDevice: " << message;
void GPUDevice::AddConsoleWarning(const char* message) {
ExecutionContext* execution_context = GetExecutionContext();
if (execution_context && allowed_console_warnings_remaining_ > 0) {
auto* console_message = MakeGarbageCollected<ConsoleMessage>(
mojom::ConsoleMessageSource::kRendering,
mojom::ConsoleMessageLevel::kWarning, message);
mojom::blink::ConsoleMessageSource::kRendering,
mojom::blink::ConsoleMessageLevel::kWarning, message);
execution_context->AddConsoleMessage(console_message);
allowed_console_warnings_remaining_--;
if (allowed_console_warnings_remaining_ == 0) {
auto* final_message = MakeGarbageCollected<ConsoleMessage>(
mojom::blink::ConsoleMessageSource::kRendering,
mojom::blink::ConsoleMessageLevel::kWarning,
"WebGPU: too many warnings, no more warnings will be reported to the "
"console for this GPUDevice.");
execution_context->AddConsoleMessage(final_message);
}
}
}
void GPUDevice::OnUncapturedError(WGPUErrorType errorType,
const char* message) {
DCHECK_NE(errorType, WGPUErrorType_NoError);
LOG(ERROR) << "GPUDevice: " << message;
AddConsoleWarning(message);
// TODO: Use device lost callback instead of uncaptured error callback.
if (errorType == WGPUErrorType_DeviceLost &&
......
......@@ -108,13 +108,13 @@ class GPUDevice final : public EventTargetWithInlineData,
const AtomicString& InterfaceName() const override;
ExecutionContext* GetExecutionContext() const override;
void AddConsoleWarning(const char* message);
private:
using LostProperty =
ScriptPromiseProperty<Member<GPUDeviceLostInfo>, ToV8UndefinedGenerator>;
void OnUncapturedError(ExecutionContext* execution_context,
WGPUErrorType errorType,
const char* message);
void OnUncapturedError(WGPUErrorType errorType, const char* message);
void OnPopErrorScopeCallback(ScriptPromiseResolver* resolver,
WGPUErrorType type,
......@@ -129,6 +129,9 @@ class GPUDevice final : public EventTargetWithInlineData,
uint64_t client_id_;
static constexpr int kMaxAllowedConsoleWarnings = 500;
int allowed_console_warnings_remaining_ = kMaxAllowedConsoleWarnings;
DISALLOW_COPY_AND_ASSIGN(GPUDevice);
};
......
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