blob: 0ffe2d1ec0754a57dd83369fd56cf2d6f2edf8cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// 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/dawn_object.h"
#include "gpu/command_buffer/client/webgpu_interface.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_device.h"
#include "third_party/blink/renderer/platform/bindings/microtask.h"
namespace blink {
DawnObjectBase::DawnObjectBase(
scoped_refptr<DawnControlClientHolder> dawn_control_client)
: dawn_control_client_(std::move(dawn_control_client)) {}
const scoped_refptr<DawnControlClientHolder>&
DawnObjectBase::GetDawnControlClient() const {
return dawn_control_client_;
}
void DawnObjectBase::setLabel(const String& value) {
// TODO: Relay label changes to Dawn
label_ = value;
}
void DawnObjectBase::EnsureFlush() {
bool needs_flush = false;
auto context_provider = GetContextProviderWeakPtr();
if (UNLIKELY(!context_provider))
return;
context_provider->ContextProvider()->WebGPUInterface()->EnsureAwaitingFlush(
&needs_flush);
if (!needs_flush) {
// We've already enqueued a task to flush, or the command buffer
// is empty. Do nothing.
return;
}
Microtask::EnqueueMicrotask(WTF::Bind(
[](scoped_refptr<DawnControlClientHolder> dawn_control_client) {
if (auto context_provider =
dawn_control_client->GetContextProviderWeakPtr()) {
context_provider->ContextProvider()
->WebGPUInterface()
->FlushAwaitingCommands();
}
},
dawn_control_client_));
}
// Flush commands up until now on this object's parent device immediately.
void DawnObjectBase::FlushNow() {
auto context_provider = GetContextProviderWeakPtr();
if (LIKELY(context_provider)) {
context_provider->ContextProvider()->WebGPUInterface()->FlushCommands();
}
}
DawnObjectImpl::DawnObjectImpl(GPUDevice* device)
: DawnObjectBase(device->GetDawnControlClient()), device_(device) {}
DawnObjectImpl::~DawnObjectImpl() = default;
WGPUDevice DawnObjectImpl::GetDeviceHandle() {
return device_->GetHandle();
}
void DawnObjectImpl::Trace(Visitor* visitor) const {
visitor->Trace(device_);
ScriptWrappable::Trace(visitor);
}
} // namespace blink
|