mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 00:17:03 +00:00
Factor wire client handlers into proper command handlers and doers
Bug: dawn:88 Change-Id: I3ab28efad7edc7d06f11aa5abae07a1bb3d7e59e Reviewed-on: https://dawn-review.googlesource.com/c/4003 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
cd4fd8e7cd
commit
1139d1c12c
@@ -105,25 +105,24 @@ namespace dawn_wire { namespace client {
|
||||
fence->requests.Enqueue(std::move(request), value);
|
||||
}
|
||||
|
||||
void ProxyClientBufferUnmap(dawnBuffer cBuffer) {
|
||||
void ClientBufferUnmap(dawnBuffer cBuffer) {
|
||||
Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer);
|
||||
|
||||
// Invalidate the local pointer, and cancel all other in-flight requests that would
|
||||
// turn into
|
||||
// errors anyway (you can't double map). This prevents race when the following happens,
|
||||
// where
|
||||
// the application code would have unmapped a buffer but still receive a callback:
|
||||
// - Client -> Server: MapRequest1, Unmap, MapRequest2
|
||||
// - Server -> Client: Result of MapRequest1
|
||||
// - Unmap locally on the client
|
||||
// - Server -> Client: Result of MapRequest2
|
||||
// turn into errors anyway (you can't double map). This prevents race when the following
|
||||
// happens, where the application code would have unmapped a buffer but still receive a
|
||||
// callback:
|
||||
// - Client -> Server: MapRequest1, Unmap, MapRequest2
|
||||
// - Server -> Client: Result of MapRequest1
|
||||
// - Unmap locally on the client
|
||||
// - Server -> Client: Result of MapRequest2
|
||||
if (buffer->mappedData) {
|
||||
// If the buffer was mapped for writing, send the update to the data to the server
|
||||
if (buffer->isWriteMapped) {
|
||||
BufferUpdateMappedDataCmd cmd;
|
||||
cmd.bufferId = buffer->id;
|
||||
cmd.dataLength = static_cast<uint32_t>(buffer->mappedDataSize);
|
||||
cmd.data = reinterpret_cast<const uint8_t*>(buffer->mappedData);
|
||||
cmd.data = static_cast<const uint8_t*>(buffer->mappedData);
|
||||
|
||||
size_t requiredSize = cmd.GetRequiredSize();
|
||||
char* allocatedBuffer =
|
||||
@@ -136,26 +135,52 @@ namespace dawn_wire { namespace client {
|
||||
}
|
||||
buffer->ClearMapRequests(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN);
|
||||
|
||||
ClientBufferUnmap(cBuffer);
|
||||
BufferUnmapCmd cmd;
|
||||
cmd.self = cBuffer;
|
||||
size_t requiredSize = cmd.GetRequiredSize();
|
||||
char* allocatedBuffer =
|
||||
static_cast<char*>(buffer->device->GetClient()->GetCmdSpace(requiredSize));
|
||||
cmd.Serialize(allocatedBuffer, *buffer->device->GetClient());
|
||||
}
|
||||
|
||||
dawnFence ProxyClientDeviceCreateFence(dawnDevice cSelf,
|
||||
dawnFenceDescriptor const* descriptor) {
|
||||
dawnFence cFence = ClientDeviceCreateFence(cSelf, descriptor);
|
||||
dawnFence ClientDeviceCreateFence(dawnDevice cSelf, dawnFenceDescriptor const* descriptor) {
|
||||
Device* device = reinterpret_cast<Device*>(cSelf);
|
||||
|
||||
DeviceCreateFenceCmd cmd;
|
||||
cmd.self = cSelf;
|
||||
auto* allocation = device->GetClient()->FenceAllocator().New(device);
|
||||
cmd.result = ObjectHandle{allocation->object->id, allocation->serial};
|
||||
cmd.descriptor = descriptor;
|
||||
|
||||
size_t requiredSize = cmd.GetRequiredSize();
|
||||
char* allocatedBuffer = static_cast<char*>(device->GetClient()->GetCmdSpace(requiredSize));
|
||||
cmd.Serialize(allocatedBuffer, *device->GetClient());
|
||||
|
||||
dawnFence cFence = reinterpret_cast<dawnFence>(allocation->object.get());
|
||||
|
||||
Fence* fence = reinterpret_cast<Fence*>(cFence);
|
||||
fence->signaledValue = descriptor->initialValue;
|
||||
fence->completedValue = descriptor->initialValue;
|
||||
return cFence;
|
||||
}
|
||||
|
||||
void ProxyClientQueueSignal(dawnQueue cQueue, dawnFence cFence, uint64_t signalValue) {
|
||||
void ClientQueueSignal(dawnQueue cQueue, dawnFence cFence, uint64_t signalValue) {
|
||||
Fence* fence = reinterpret_cast<Fence*>(cFence);
|
||||
if (signalValue <= fence->signaledValue) {
|
||||
fence->device->HandleError("Fence value less than or equal to signaled value");
|
||||
return;
|
||||
}
|
||||
fence->signaledValue = signalValue;
|
||||
ClientQueueSignal(cQueue, cFence, signalValue);
|
||||
|
||||
QueueSignalCmd cmd;
|
||||
cmd.self = cQueue;
|
||||
cmd.fence = cFence;
|
||||
cmd.signalValue = signalValue;
|
||||
|
||||
size_t requiredSize = cmd.GetRequiredSize();
|
||||
char* allocatedBuffer =
|
||||
static_cast<char*>(fence->device->GetClient()->GetCmdSpace(requiredSize));
|
||||
cmd.Serialize(allocatedBuffer, *fence->device->GetClient());
|
||||
}
|
||||
|
||||
void ClientDeviceReference(dawnDevice) {
|
||||
|
||||
@@ -18,38 +18,24 @@
|
||||
|
||||
namespace dawn_wire { namespace client {
|
||||
|
||||
bool Client::HandleDeviceErrorCallback(const char** commands, size_t* size) {
|
||||
ReturnDeviceErrorCallbackCmd cmd;
|
||||
DeserializeResult deserializeResult = cmd.Deserialize(commands, size, &mAllocator);
|
||||
|
||||
if (deserializeResult == DeserializeResult::FatalError) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DAWN_ASSERT(cmd.message != nullptr);
|
||||
mDevice->HandleError(cmd.message);
|
||||
|
||||
bool Client::DoDeviceErrorCallback(const char* message) {
|
||||
DAWN_ASSERT(message != nullptr);
|
||||
mDevice->HandleError(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Client::HandleBufferMapReadAsyncCallback(const char** commands, size_t* size) {
|
||||
ReturnBufferMapReadAsyncCallbackCmd cmd;
|
||||
DeserializeResult deserializeResult = cmd.Deserialize(commands, size, &mAllocator);
|
||||
|
||||
if (deserializeResult == DeserializeResult::FatalError) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* buffer = mDevice->GetClient()->BufferAllocator().GetObject(cmd.buffer.id);
|
||||
uint32_t bufferSerial = mDevice->GetClient()->BufferAllocator().GetSerial(cmd.buffer.id);
|
||||
|
||||
bool Client::DoBufferMapReadAsyncCallback(Buffer* buffer,
|
||||
uint32_t requestSerial,
|
||||
uint32_t status,
|
||||
uint32_t count,
|
||||
const uint8_t* data) {
|
||||
// The buffer might have been deleted or recreated so this isn't an error.
|
||||
if (buffer == nullptr || bufferSerial != cmd.buffer.serial) {
|
||||
if (buffer == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// The requests can have been deleted via an Unmap so this isn't an error.
|
||||
auto requestIt = buffer->requests.find(cmd.requestSerial);
|
||||
auto requestIt = buffer->requests.find(requestSerial);
|
||||
if (requestIt == buffer->requests.end()) {
|
||||
return true;
|
||||
}
|
||||
@@ -66,14 +52,14 @@ namespace dawn_wire { namespace client {
|
||||
|
||||
// On success, we copy the data locally because the IPC buffer isn't valid outside of this
|
||||
// function
|
||||
if (cmd.status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS) {
|
||||
if (status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS) {
|
||||
// The server didn't send the right amount of data, this is an error and could cause
|
||||
// the application to crash if we did call the callback.
|
||||
if (request.size != cmd.dataLength) {
|
||||
if (request.size != count) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ASSERT(cmd.data != nullptr);
|
||||
ASSERT(data != nullptr);
|
||||
|
||||
if (buffer->mappedData != nullptr) {
|
||||
return false;
|
||||
@@ -82,36 +68,28 @@ namespace dawn_wire { namespace client {
|
||||
buffer->isWriteMapped = false;
|
||||
buffer->mappedDataSize = request.size;
|
||||
buffer->mappedData = malloc(request.size);
|
||||
memcpy(buffer->mappedData, cmd.data, request.size);
|
||||
memcpy(buffer->mappedData, data, request.size);
|
||||
|
||||
request.readCallback(static_cast<dawnBufferMapAsyncStatus>(cmd.status),
|
||||
buffer->mappedData, request.userdata);
|
||||
request.readCallback(static_cast<dawnBufferMapAsyncStatus>(status), buffer->mappedData,
|
||||
request.userdata);
|
||||
} else {
|
||||
request.readCallback(static_cast<dawnBufferMapAsyncStatus>(cmd.status), nullptr,
|
||||
request.readCallback(static_cast<dawnBufferMapAsyncStatus>(status), nullptr,
|
||||
request.userdata);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Client::HandleBufferMapWriteAsyncCallback(const char** commands, size_t* size) {
|
||||
ReturnBufferMapWriteAsyncCallbackCmd cmd;
|
||||
DeserializeResult deserializeResult = cmd.Deserialize(commands, size, &mAllocator);
|
||||
|
||||
if (deserializeResult == DeserializeResult::FatalError) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* buffer = mDevice->GetClient()->BufferAllocator().GetObject(cmd.buffer.id);
|
||||
uint32_t bufferSerial = mDevice->GetClient()->BufferAllocator().GetSerial(cmd.buffer.id);
|
||||
|
||||
bool Client::DoBufferMapWriteAsyncCallback(Buffer* buffer,
|
||||
uint32_t requestSerial,
|
||||
uint32_t status) {
|
||||
// The buffer might have been deleted or recreated so this isn't an error.
|
||||
if (buffer == nullptr || bufferSerial != cmd.buffer.serial) {
|
||||
if (buffer == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// The requests can have been deleted via an Unmap so this isn't an error.
|
||||
auto requestIt = buffer->requests.find(cmd.requestSerial);
|
||||
auto requestIt = buffer->requests.find(requestSerial);
|
||||
if (requestIt == buffer->requests.end()) {
|
||||
return true;
|
||||
}
|
||||
@@ -128,7 +106,7 @@ namespace dawn_wire { namespace client {
|
||||
|
||||
// On success, we copy the data locally because the IPC buffer isn't valid outside of this
|
||||
// function
|
||||
if (cmd.status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS) {
|
||||
if (status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS) {
|
||||
if (buffer->mappedData != nullptr) {
|
||||
return false;
|
||||
}
|
||||
@@ -138,33 +116,23 @@ namespace dawn_wire { namespace client {
|
||||
buffer->mappedData = malloc(request.size);
|
||||
memset(buffer->mappedData, 0, request.size);
|
||||
|
||||
request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(cmd.status),
|
||||
buffer->mappedData, request.userdata);
|
||||
request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(status), buffer->mappedData,
|
||||
request.userdata);
|
||||
} else {
|
||||
request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(cmd.status), nullptr,
|
||||
request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(status), nullptr,
|
||||
request.userdata);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Client::HandleFenceUpdateCompletedValue(const char** commands, size_t* size) {
|
||||
ReturnFenceUpdateCompletedValueCmd cmd;
|
||||
DeserializeResult deserializeResult = cmd.Deserialize(commands, size, &mAllocator);
|
||||
|
||||
if (deserializeResult == DeserializeResult::FatalError) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* fence = mDevice->GetClient()->FenceAllocator().GetObject(cmd.fence.id);
|
||||
uint32_t fenceSerial = mDevice->GetClient()->FenceAllocator().GetSerial(cmd.fence.id);
|
||||
|
||||
bool Client::DoFenceUpdateCompletedValue(Fence* fence, uint64_t value) {
|
||||
// The fence might have been deleted or recreated so this isn't an error.
|
||||
if (fence == nullptr || fenceSerial != cmd.fence.serial) {
|
||||
if (fence == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
fence->completedValue = cmd.value;
|
||||
fence->completedValue = value;
|
||||
fence->CheckPassedFences();
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user