mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 17:05:31 +00:00
dawn_wire: Add support for injecting/reserving swapchains
This will help experiment using dawn_wire for remoting WebGPU to render on the screen. Bug: None Change-Id: I9a60ff8c3889ec917f6fd56e4cbb1ffef639748d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/47621 Auto-Submit: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Brandon Jones <bajones@chromium.org> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
b676602188
commit
e190045664
@@ -33,6 +33,10 @@ namespace dawn_wire {
|
||||
return mImpl->ReserveTexture(device);
|
||||
}
|
||||
|
||||
ReservedSwapChain WireClient::ReserveSwapChain(WGPUDevice device) {
|
||||
return mImpl->ReserveSwapChain(device);
|
||||
}
|
||||
|
||||
ReservedDevice WireClient::ReserveDevice() {
|
||||
return mImpl->ReserveDevice();
|
||||
}
|
||||
@@ -41,6 +45,10 @@ namespace dawn_wire {
|
||||
mImpl->ReclaimTextureReservation(reservation);
|
||||
}
|
||||
|
||||
void WireClient::ReclaimSwapChainReservation(const ReservedSwapChain& reservation) {
|
||||
mImpl->ReclaimSwapChainReservation(reservation);
|
||||
}
|
||||
|
||||
void WireClient::ReclaimDeviceReservation(const ReservedDevice& reservation) {
|
||||
mImpl->ReclaimDeviceReservation(reservation);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,14 @@ namespace dawn_wire {
|
||||
return mImpl->InjectTexture(texture, id, generation, deviceId, deviceGeneration);
|
||||
}
|
||||
|
||||
bool WireServer::InjectSwapChain(WGPUSwapChain swapchain,
|
||||
uint32_t id,
|
||||
uint32_t generation,
|
||||
uint32_t deviceId,
|
||||
uint32_t deviceGeneration) {
|
||||
return mImpl->InjectSwapChain(swapchain, id, generation, deviceId, deviceGeneration);
|
||||
}
|
||||
|
||||
bool WireServer::InjectDevice(WGPUDevice device, uint32_t id, uint32_t generation) {
|
||||
return mImpl->InjectDevice(device, id, generation);
|
||||
}
|
||||
|
||||
@@ -96,6 +96,18 @@ namespace dawn_wire { namespace client {
|
||||
return result;
|
||||
}
|
||||
|
||||
ReservedSwapChain Client::ReserveSwapChain(WGPUDevice device) {
|
||||
auto* allocation = SwapChainAllocator().New(this);
|
||||
|
||||
ReservedSwapChain result;
|
||||
result.swapchain = ToAPI(allocation->object.get());
|
||||
result.id = allocation->object->id;
|
||||
result.generation = allocation->generation;
|
||||
result.deviceId = FromAPI(device)->id;
|
||||
result.deviceGeneration = DeviceAllocator().GetGeneration(FromAPI(device)->id);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReservedDevice Client::ReserveDevice() {
|
||||
auto* allocation = DeviceAllocator().New(this);
|
||||
|
||||
@@ -110,6 +122,10 @@ namespace dawn_wire { namespace client {
|
||||
TextureAllocator().Free(FromAPI(reservation.texture));
|
||||
}
|
||||
|
||||
void Client::ReclaimSwapChainReservation(const ReservedSwapChain& reservation) {
|
||||
SwapChainAllocator().Free(FromAPI(reservation.swapchain));
|
||||
}
|
||||
|
||||
void Client::ReclaimDeviceReservation(const ReservedDevice& reservation) {
|
||||
DeviceAllocator().Free(FromAPI(reservation.device));
|
||||
}
|
||||
|
||||
@@ -44,9 +44,11 @@ namespace dawn_wire { namespace client {
|
||||
}
|
||||
|
||||
ReservedTexture ReserveTexture(WGPUDevice device);
|
||||
ReservedSwapChain ReserveSwapChain(WGPUDevice device);
|
||||
ReservedDevice ReserveDevice();
|
||||
|
||||
void ReclaimTextureReservation(const ReservedTexture& reservation);
|
||||
void ReclaimSwapChainReservation(const ReservedSwapChain& reservation);
|
||||
void ReclaimDeviceReservation(const ReservedDevice& reservation);
|
||||
|
||||
template <typename Cmd>
|
||||
|
||||
@@ -72,6 +72,38 @@ namespace dawn_wire { namespace server {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Server::InjectSwapChain(WGPUSwapChain swapchain,
|
||||
uint32_t id,
|
||||
uint32_t generation,
|
||||
uint32_t deviceId,
|
||||
uint32_t deviceGeneration) {
|
||||
ASSERT(swapchain != nullptr);
|
||||
ObjectData<WGPUDevice>* device = DeviceObjects().Get(deviceId);
|
||||
if (device == nullptr || device->generation != deviceGeneration) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ObjectData<WGPUSwapChain>* data = SwapChainObjects().Allocate(id);
|
||||
if (data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
data->handle = swapchain;
|
||||
data->generation = generation;
|
||||
data->state = AllocationState::Allocated;
|
||||
data->deviceInfo = device->info.get();
|
||||
|
||||
if (!TrackDeviceChild(data->deviceInfo, ObjectType::SwapChain, id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The texture is externally owned so it shouldn't be destroyed when we receive a destroy
|
||||
// message from the client. Add a reference to counterbalance the eventual release.
|
||||
mProcs.swapChainReference(swapchain);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Server::InjectDevice(WGPUDevice device, uint32_t id, uint32_t generation) {
|
||||
ASSERT(device != nullptr);
|
||||
ObjectData<WGPUDevice>* data = DeviceObjects().Allocate(id);
|
||||
|
||||
@@ -180,6 +180,12 @@ namespace dawn_wire { namespace server {
|
||||
uint32_t deviceId,
|
||||
uint32_t deviceGeneration);
|
||||
|
||||
bool InjectSwapChain(WGPUSwapChain swapchain,
|
||||
uint32_t id,
|
||||
uint32_t generation,
|
||||
uint32_t deviceId,
|
||||
uint32_t deviceGeneration);
|
||||
|
||||
bool InjectDevice(WGPUDevice device, uint32_t id, uint32_t generation);
|
||||
|
||||
WGPUDevice GetDevice(uint32_t id, uint32_t generation);
|
||||
|
||||
Reference in New Issue
Block a user