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

@@ -38,6 +38,12 @@ namespace dawn_wire {
uint32_t deviceGeneration;
};
struct ReservedDevice {
WGPUDevice device;
uint32_t id;
uint32_t generation;
};
struct DAWN_WIRE_EXPORT WireClientDescriptor {
CommandSerializer* serializer;
client::MemoryTransferService* memoryTransferService = nullptr;
@@ -53,6 +59,7 @@ namespace dawn_wire {
size_t size) override final;
ReservedTexture ReserveTexture(WGPUDevice device);
ReservedDevice ReserveDevice();
// Disconnects the client.
// Commands allocated after this point will not be sent.

View File

@@ -50,6 +50,17 @@ namespace dawn_wire {
uint32_t deviceId = 1,
uint32_t deviceGeneration = 0);
bool InjectDevice(WGPUDevice device, uint32_t id, uint32_t generation);
// Look up a device by (id, generation) pair. Returns nullptr if the generation
// has expired or the id is not found.
// The Wire does not have destroy hooks to allow an embedder to observe when an object
// has been destroyed, but in Chrome, we need to know the list of live devices so we
// can call device.Tick() on all of them periodically to ensure progress on asynchronous
// work is made. Getting this list can be done by tracking the (id, generation) of
// previously injected devices, and observing if GetDevice(id, generation) returns non-null.
WGPUDevice GetDevice(uint32_t id, uint32_t generation);
private:
std::unique_ptr<server::Server> mImpl;
};