dawn_wire: Add Reserve/InjectDevice

Now that the wire does enough tracking to prevent a malicious client
from freeing a device before its child objects, and the device is no
longer a "special" object with regard to reference/release, it is
safe to support multiple devices on the wire. The simplest way to
use this in WebGPU (to fix createReadyRenderPipeline validation)
is to add a reserve/inject device API similar to the one we use for
swapchain textures.

Bug: dawn:565
Change-Id: Ie956aff528c5610c9ecc5c189dab2d22185cb572
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/37800
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng
2021-01-19 19:27:52 +00:00
committed by Commit Bot service account
parent b830da7d6e
commit 8bcde8e394
18 changed files with 377 additions and 45 deletions

View File

@@ -85,8 +85,13 @@ namespace dawn_wire { namespace client {
}
WGPUDevice Client::GetDevice() {
// This function is deprecated. The concept of a "default" device on the wire
// will be removed in favor of ReserveDevice/InjectDevice.
if (mDevice == nullptr) {
mDevice = DeviceAllocator().New(this)->object.get();
ReservedDevice reservation = ReserveDevice();
mDevice = FromAPI(reservation.device);
ASSERT(reservation.id == 1);
ASSERT(reservation.generation == 0);
}
return reinterpret_cast<WGPUDeviceImpl*>(mDevice);
}
@@ -103,6 +108,16 @@ namespace dawn_wire { namespace client {
return result;
}
ReservedDevice Client::ReserveDevice() {
auto* allocation = DeviceAllocator().New(this);
ReservedDevice result;
result.device = ToAPI(allocation->object.get());
result.id = allocation->object->id;
result.generation = allocation->generation;
return result;
}
void Client::Disconnect() {
mDisconnected = true;
mSerializer = ChunkedCommandSerializer(NoopCommandSerializer::GetInstance());