mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-19 01:46:35 +00:00
dawn_wire: Make all objects owned by the client
This removes the logic where the Client owns the Device and the Device owns all other objects. Ownership should be tracked in dawn_native either with refcounting or validation to disallow operations after an object's parent has been destroyed. This simplifies the wire client code in that the client only tracks allocated handles and does not manage parent/child lifetimes. This is an important simplification so we can support multiple WebGPU instances, adapters, and devices on a single wire. Bug: dawn:384 Change-Id: I8ecc7c368130b8917202150c467b5f0e7d4b753e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/37000 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
f6ef7530ab
commit
f0d7cc4f5a
@@ -57,10 +57,23 @@ namespace dawn_wire { namespace client {
|
||||
}
|
||||
|
||||
void Client::DestroyAllObjects() {
|
||||
while (!mDevices.empty()) {
|
||||
// Note: We don't send a DestroyObject command for the device
|
||||
// since freeing a device object is done out of band.
|
||||
DeviceAllocator().Free(static_cast<Device*>(mDevices.head()->value()));
|
||||
for (auto& objectList : mObjects) {
|
||||
ObjectType objectType = static_cast<ObjectType>(&objectList - mObjects.data());
|
||||
while (!objectList.empty()) {
|
||||
ObjectBase* object = objectList.head()->value();
|
||||
if (object == mDevice) {
|
||||
// Note: We don't send a DestroyObject command for the device
|
||||
// since freeing a device object is done out of band.
|
||||
DeviceAllocator().Free(mDevice);
|
||||
continue;
|
||||
}
|
||||
|
||||
DestroyObjectCmd cmd;
|
||||
cmd.objectType = objectType;
|
||||
cmd.objectId = object->id;
|
||||
SerializeCommand(cmd);
|
||||
FreeObject(objectType, object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +84,8 @@ namespace dawn_wire { namespace client {
|
||||
return reinterpret_cast<WGPUDeviceImpl*>(mDevice);
|
||||
}
|
||||
|
||||
ReservedTexture Client::ReserveTexture(WGPUDevice cDevice) {
|
||||
Device* device = FromAPI(cDevice);
|
||||
auto* allocation = TextureAllocator().New(device);
|
||||
ReservedTexture Client::ReserveTexture(WGPUDevice device) {
|
||||
auto* allocation = TextureAllocator().New(this);
|
||||
|
||||
ReservedTexture result;
|
||||
result.texture = ToAPI(allocation->object.get());
|
||||
@@ -87,12 +99,14 @@ namespace dawn_wire { namespace client {
|
||||
mSerializer = ChunkedCommandSerializer(NoopCommandSerializer::GetInstance());
|
||||
if (mDevice != nullptr) {
|
||||
mDevice->HandleDeviceLost("GPU connection lost");
|
||||
mDevice->CancelCallbacksForDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void Client::TrackObject(Device* device) {
|
||||
mDevices.Append(device);
|
||||
for (auto& objectList : mObjects) {
|
||||
LinkNode<ObjectBase>* object = objectList.head();
|
||||
while (object != objectList.end()) {
|
||||
object->value()->CancelCallbacksForDisconnect();
|
||||
object = object->next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Client::IsDisconnected() const {
|
||||
|
||||
Reference in New Issue
Block a user