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:
Austin Eng 2019-01-30 03:00:17 +00:00 committed by Commit Bot service account
parent cd4fd8e7cd
commit 1139d1c12c
12 changed files with 171 additions and 123 deletions

View File

@ -764,6 +764,7 @@ dawn_generator("libdawn_wire_gen") {
"dawn_wire/client/ApiProcs_autogen.cpp", "dawn_wire/client/ApiProcs_autogen.cpp",
"dawn_wire/client/ApiProcs_autogen.h", "dawn_wire/client/ApiProcs_autogen.h",
"dawn_wire/client/ClientBase_autogen.h", "dawn_wire/client/ClientBase_autogen.h",
"dawn_wire/client/ClientDoers_autogen.cpp",
"dawn_wire/client/ClientHandlers_autogen.cpp", "dawn_wire/client/ClientHandlers_autogen.cpp",
"dawn_wire/client/ClientPrototypes_autogen.inl", "dawn_wire/client/ClientPrototypes_autogen.inl",
"dawn_wire/server/ServerBase_autogen.h", "dawn_wire/server/ServerBase_autogen.h",
@ -794,7 +795,7 @@ dawn_component("libdawn_wire") {
"src/dawn_wire/client/Buffer.h", "src/dawn_wire/client/Buffer.h",
"src/dawn_wire/client/Client.cpp", "src/dawn_wire/client/Client.cpp",
"src/dawn_wire/client/Client.h", "src/dawn_wire/client/Client.h",
"src/dawn_wire/client/ClientHandlers.cpp", "src/dawn_wire/client/ClientDoers.cpp",
"src/dawn_wire/client/Device.cpp", "src/dawn_wire/client/Device.cpp",
"src/dawn_wire/client/Device.h", "src/dawn_wire/client/Device.h",
"src/dawn_wire/client/Fence.cpp", "src/dawn_wire/client/Fence.cpp",

View File

@ -34,14 +34,14 @@
}, },
"return commands": { "return commands": {
"buffer map read async callback": [ "buffer map read async callback": [
{ "name": "buffer", "type": "ObjectHandle" }, { "name": "buffer", "type": "ObjectHandle", "handle_type": "buffer" },
{ "name": "request serial", "type": "uint32_t" }, { "name": "request serial", "type": "uint32_t" },
{ "name": "status", "type": "uint32_t" }, { "name": "status", "type": "uint32_t" },
{ "name": "data length", "type": "uint32_t" }, { "name": "data length", "type": "uint32_t" },
{ "name": "data", "type": "uint8_t", "annotation": "const*", "length": "data length" } { "name": "data", "type": "uint8_t", "annotation": "const*", "length": "data length" }
], ],
"buffer map write async callback": [ "buffer map write async callback": [
{ "name": "buffer", "type": "ObjectHandle" }, { "name": "buffer", "type": "ObjectHandle", "handle_type": "buffer" },
{ "name": "request serial", "type": "uint32_t" }, { "name": "request serial", "type": "uint32_t" },
{ "name": "status", "type": "uint32_t" } { "name": "status", "type": "uint32_t" }
], ],
@ -49,7 +49,7 @@
{ "name": "message", "type": "char", "annotation": "const*", "length": "strlen" } { "name": "message", "type": "char", "annotation": "const*", "length": "strlen" }
], ],
"fence update completed value": [ "fence update completed value": [
{ "name": "fence", "type": "ObjectHandle" }, { "name": "fence", "type": "ObjectHandle", "handle_type": "fence" },
{ "name": "value", "type": "uint64_t" } { "name": "value", "type": "uint64_t" }
] ]
}, },
@ -57,9 +57,10 @@
"client_side_commands": [ "client_side_commands": [
"FenceGetCompletedValue" "FenceGetCompletedValue"
], ],
"client_proxied_commands": [ "client_handwritten_commands": [
"BufferUnmap", "BufferUnmap",
"DeviceCreateFence", "DeviceCreateFence",
"FenceGetCompletedValue",
"QueueSignal" "QueueSignal"
], ],
"client_special_objects": [ "client_special_objects": [

View File

@ -84,6 +84,11 @@ class RecordMember:
self.length = None self.length = None
self.optional = optional self.optional = optional
self.is_return_value = is_return_value self.is_return_value = is_return_value
self.handle_type = None
def set_handle_type(self, handle_type):
assert self.type.dict_name == "ObjectHandle"
self.handle_type = handle_type
Method = namedtuple('Method', ['name', 'return_type', 'arguments']) Method = namedtuple('Method', ['name', 'return_type', 'arguments'])
class ObjectType(Type): class ObjectType(Type):
@ -130,6 +135,9 @@ def linked_record_members(json_data, types):
member = RecordMember(Name(m['name']), types[m['type']], member = RecordMember(Name(m['name']), types[m['type']],
m.get('annotation', 'value'), m.get('optional', False), m.get('annotation', 'value'), m.get('optional', False),
m.get('is_return_value', False)) m.get('is_return_value', False))
handle_type = m.get('handle_type')
if handle_type:
member.set_handle_type(types[handle_type])
members.append(member) members.append(member)
members_by_name[member.name.canonical_case()] = member members_by_name[member.name.canonical_case()] = member

View File

@ -388,6 +388,7 @@ def get_renders_for_targets(api_params, wire_json, targets):
renders.append(FileRender('dawn_wire/client/ApiProcs.cpp', 'dawn_wire/client/ApiProcs_autogen.cpp', wire_params)) renders.append(FileRender('dawn_wire/client/ApiProcs.cpp', 'dawn_wire/client/ApiProcs_autogen.cpp', wire_params))
renders.append(FileRender('dawn_wire/client/ApiProcs.h', 'dawn_wire/client/ApiProcs_autogen.h', wire_params)) renders.append(FileRender('dawn_wire/client/ApiProcs.h', 'dawn_wire/client/ApiProcs_autogen.h', wire_params))
renders.append(FileRender('dawn_wire/client/ClientBase.h', 'dawn_wire/client/ClientBase_autogen.h', wire_params)) renders.append(FileRender('dawn_wire/client/ClientBase.h', 'dawn_wire/client/ClientBase_autogen.h', wire_params))
renders.append(FileRender('dawn_wire/client/ClientDoers.cpp', 'dawn_wire/client/ClientDoers_autogen.cpp', wire_params))
renders.append(FileRender('dawn_wire/client/ClientHandlers.cpp', 'dawn_wire/client/ClientHandlers_autogen.cpp', wire_params)) renders.append(FileRender('dawn_wire/client/ClientHandlers.cpp', 'dawn_wire/client/ClientHandlers_autogen.cpp', wire_params))
renders.append(FileRender('dawn_wire/client/ClientPrototypes.inl', 'dawn_wire/client/ClientPrototypes_autogen.inl', wire_params)) renders.append(FileRender('dawn_wire/client/ClientPrototypes.inl', 'dawn_wire/client/ClientPrototypes_autogen.inl', wire_params))
renders.append(FileRender('dawn_wire/server/ServerBase.h', 'dawn_wire/server/ServerBase_autogen.h', wire_params)) renders.append(FileRender('dawn_wire/server/ServerBase.h', 'dawn_wire/server/ServerBase_autogen.h', wire_params))

View File

@ -24,7 +24,7 @@ namespace dawn_wire { namespace client {
{% for method in type.methods %} {% for method in type.methods %}
{% set Suffix = as_MethodSuffix(type.name, method.name) %} {% set Suffix = as_MethodSuffix(type.name, method.name) %}
{% if Suffix not in client_side_commands %} {% if Suffix not in client_handwritten_commands %}
{{as_cType(method.return_type.name)}} Client{{Suffix}}( {{as_cType(method.return_type.name)}} Client{{Suffix}}(
{{-cType}} cSelf {{-cType}} cSelf
{%- for arg in method.arguments -%} {%- for arg in method.arguments -%}
@ -122,11 +122,7 @@ namespace dawn_wire { namespace client {
{% for type in by_category["object"] %} {% for type in by_category["object"] %}
{% for method in native_methods(type) %} {% for method in native_methods(type) %}
{% set suffix = as_MethodSuffix(type.name, method.name) %} {% set suffix = as_MethodSuffix(type.name, method.name) %}
{% if suffix in client_proxied_commands %}
table.{{as_varName(type.name, method.name)}} = ProxyClient{{suffix}};
{% else %}
table.{{as_varName(type.name, method.name)}} = Client{{suffix}}; table.{{as_varName(type.name, method.name)}} = Client{{suffix}};
{% endif %}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
return table; return table;

View File

@ -24,14 +24,6 @@ namespace dawn_wire { namespace client {
{% set cType = as_cType(type.name) %} {% set cType = as_cType(type.name) %}
{% for method in native_methods(type) %} {% for method in native_methods(type) %}
{% set Suffix = as_MethodSuffix(type.name, method.name) %} {% set Suffix = as_MethodSuffix(type.name, method.name) %}
{% if Suffix in client_proxied_commands %}
{{as_cType(method.return_type.name)}} ProxyClient{{Suffix}}(
{{-cType}} cSelf
{%- for arg in method.arguments -%}
, {{as_annotated_cType(arg)}}
{%- endfor -%}
);
{% endif %}
{{as_cType(method.return_type.name)}} Client{{Suffix}}( {{as_cType(method.return_type.name)}} Client{{Suffix}}(
{{-cType}} cSelf {{-cType}} cSelf
{%- for arg in method.arguments -%} {%- for arg in method.arguments -%}

View File

@ -0,0 +1,39 @@
//* Copyright 2019 The Dawn Authors
//*
//* Licensed under the Apache License, Version 2.0 (the "License");
//* you may not use this file except in compliance with the License.
//* You may obtain a copy of the License at
//*
//* http://www.apache.org/licenses/LICENSE-2.0
//*
//* Unless required by applicable law or agreed to in writing, software
//* distributed under the License is distributed on an "AS IS" BASIS,
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//* See the License for the specific language governing permissions and
//* limitations under the License.
#include "dawn_wire/client/Client.h"
#include <string>
namespace dawn_wire {
namespace client {
{% for type in by_category["object"] if type.is_builder %}
{% set Type = type.name.CamelCase() %}
bool Client::Do{{Type}}ErrorCallback({{type.built_type.name.CamelCase()}}* object, uint32_t status, const char* message) {
//* The object might have been deleted or a new object created with the same ID.
if (object == nullptr) {
return true;
}
bool called = object->builderCallback.Call(static_cast<dawnBuilderErrorStatus>(status), message);
//* Unhandled builder errors are forwarded to the device
if (!called && status != DAWN_BUILDER_ERROR_STATUS_SUCCESS && status != DAWN_BUILDER_ERROR_STATUS_UNKNOWN) {
mDevice->HandleError(("Unhandled builder error: " + std::string(message)).c_str());
}
return true;
}
{% endfor %}
}
}

View File

@ -18,34 +18,38 @@
#include <string> #include <string>
namespace dawn_wire { namespace client { namespace dawn_wire { namespace client {
{% for type in by_category["object"] if type.is_builder %} {% for command in cmd_records["return command"] %}
{% set Type = type.name.CamelCase() %} bool Client::Handle{{command.name.CamelCase()}}(const char** commands, size_t* size) {
bool Client::Handle{{Type}}ErrorCallback(const char** commands, size_t* size) { Return{{command.name.CamelCase()}}Cmd cmd;
Return{{Type}}ErrorCallbackCmd cmd;
DeserializeResult deserializeResult = cmd.Deserialize(commands, size, &mAllocator); DeserializeResult deserializeResult = cmd.Deserialize(commands, size, &mAllocator);
if (deserializeResult == DeserializeResult::FatalError) { if (deserializeResult == DeserializeResult::FatalError) {
return false; return false;
} }
DAWN_ASSERT(cmd.message != nullptr); {% for member in command.members if member.handle_type %}
{% set Type = member.handle_type.name.CamelCase() %}
{% set name = as_varName(member.name) %}
auto* builtObject = mDevice->GetClient()->{{type.built_type.name.CamelCase()}}Allocator().GetObject(cmd.builtObject.id); {% if member.type.dict_name == "ObjectHandle" %}
uint32_t objectSerial = mDevice->GetClient()->{{type.built_type.name.CamelCase()}}Allocator().GetSerial(cmd.builtObject.id); {{Type}}* {{name}} = {{Type}}Allocator().GetObject(cmd.{{name}}.id);
uint32_t {{name}}Serial = {{Type}}Allocator().GetSerial(cmd.{{name}}.id);
//* The object might have been deleted or a new object created with the same ID. if ({{name}}Serial != cmd.{{name}}.serial) {
if (builtObject == nullptr || objectSerial != cmd.builtObject.serial) { {{name}} = nullptr;
return true;
} }
{% endif %}
{% endfor %}
bool called = builtObject->builderCallback.Call(static_cast<dawnBuilderErrorStatus>(cmd.status), cmd.message); return Do{{command.name.CamelCase()}}(
{%- for member in command.members -%}
// Unhandled builder errors are forwarded to the device {%- if member.handle_type -%}
if (!called && cmd.status != DAWN_BUILDER_ERROR_STATUS_SUCCESS && cmd.status != DAWN_BUILDER_ERROR_STATUS_UNKNOWN) { {{as_varName(member.name)}}
mDevice->HandleError(("Unhandled builder error: " + std::string(cmd.message)).c_str()); {%- else -%}
} cmd.{{as_varName(member.name)}}
{%- endif -%}
return true; {%- if not loop.last -%}, {% endif %}
{%- endfor -%}
);
} }
{% endfor %} {% endfor %}

View File

@ -16,3 +16,17 @@
{% for command in cmd_records["return command"] %} {% for command in cmd_records["return command"] %}
bool Handle{{command.name.CamelCase()}}(const char** commands, size_t* size); bool Handle{{command.name.CamelCase()}}(const char** commands, size_t* size);
{% endfor %} {% endfor %}
//* Return command doers
{% for command in cmd_records["return command"] %}
bool Do{{command.name.CamelCase()}}(
{%- for member in command.members -%}
{%- if member.handle_type -%}
{{as_cppType(member.handle_type.name)}}* {{as_varName(member.name)}}
{%- else -%}
{{as_annotated_cppType(member)}}
{%- endif -%}
{%- if not loop.last -%}, {% endif %}
{%- endfor -%}
);
{% endfor %}

View File

@ -27,13 +27,9 @@ def compute_wire_params(api_params, wire_json):
commands = [] commands = []
return_commands = [] return_commands = []
object_result_member = common.RecordMember(Name('result'), types['ObjectHandle'], 'value', False, True)
string_message_member = common.RecordMember(Name('message'), types['char'], 'const*', False, False) string_message_member = common.RecordMember(Name('message'), types['char'], 'const*', False, False)
string_message_member.length = 'strlen' string_message_member.length = 'strlen'
built_object_member = common.RecordMember(Name('built object'), types['ObjectHandle'], 'value', False, False)
callback_status_member = common.RecordMember(Name('status'), types['uint32_t'], 'value', False, False) callback_status_member = common.RecordMember(Name('status'), types['uint32_t'], 'value', False, False)
# Generate commands from object methods # Generate commands from object methods
@ -50,7 +46,9 @@ def compute_wire_params(api_params, wire_json):
# Client->Server commands that return an object return the result object handle # Client->Server commands that return an object return the result object handle
if method.return_type.category == 'object': if method.return_type.category == 'object':
members.append(object_result_member) result = common.RecordMember(Name('result'), types['ObjectHandle'], 'value', False, True)
result.set_handle_type(method.return_type)
members.append(result)
command_name = concat_names(api_object.name, method.name) command_name = concat_names(api_object.name, method.name)
command = common.Command(command_name, members) command = common.Command(command_name, members)
@ -63,9 +61,10 @@ def compute_wire_params(api_params, wire_json):
# This can be removed when WebGPU error handling is implemented # This can be removed when WebGPU error handling is implemented
if api_object.is_builder: if api_object.is_builder:
command_name = concat_names(api_object.name, Name('error callback')) command_name = concat_names(api_object.name, Name('error callback'))
built_object = common.RecordMember(Name('built object'), types['ObjectHandle'], 'value', False, False)
built_object.set_handle_type(api_object.built_type)
command = common.Command(command_name, [ command = common.Command(command_name, [
built_object_member, built_object,
callback_status_member, callback_status_member,
string_message_member, string_message_member,
]) ])

View File

@ -105,14 +105,13 @@ namespace dawn_wire { namespace client {
fence->requests.Enqueue(std::move(request), value); fence->requests.Enqueue(std::move(request), value);
} }
void ProxyClientBufferUnmap(dawnBuffer cBuffer) { void ClientBufferUnmap(dawnBuffer cBuffer) {
Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer); Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer);
// Invalidate the local pointer, and cancel all other in-flight requests that would // Invalidate the local pointer, and cancel all other in-flight requests that would
// turn into // turn into errors anyway (you can't double map). This prevents race when the following
// errors anyway (you can't double map). This prevents race when the following happens, // happens, where the application code would have unmapped a buffer but still receive a
// where // callback:
// the application code would have unmapped a buffer but still receive a callback:
// - Client -> Server: MapRequest1, Unmap, MapRequest2 // - Client -> Server: MapRequest1, Unmap, MapRequest2
// - Server -> Client: Result of MapRequest1 // - Server -> Client: Result of MapRequest1
// - Unmap locally on the client // - Unmap locally on the client
@ -123,7 +122,7 @@ namespace dawn_wire { namespace client {
BufferUpdateMappedDataCmd cmd; BufferUpdateMappedDataCmd cmd;
cmd.bufferId = buffer->id; cmd.bufferId = buffer->id;
cmd.dataLength = static_cast<uint32_t>(buffer->mappedDataSize); 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(); size_t requiredSize = cmd.GetRequiredSize();
char* allocatedBuffer = char* allocatedBuffer =
@ -136,26 +135,52 @@ namespace dawn_wire { namespace client {
} }
buffer->ClearMapRequests(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN); 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, dawnFence ClientDeviceCreateFence(dawnDevice cSelf, dawnFenceDescriptor const* descriptor) {
dawnFenceDescriptor const* descriptor) { Device* device = reinterpret_cast<Device*>(cSelf);
dawnFence cFence = ClientDeviceCreateFence(cSelf, descriptor);
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* fence = reinterpret_cast<Fence*>(cFence);
fence->signaledValue = descriptor->initialValue; fence->signaledValue = descriptor->initialValue;
fence->completedValue = descriptor->initialValue; fence->completedValue = descriptor->initialValue;
return cFence; 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); Fence* fence = reinterpret_cast<Fence*>(cFence);
if (signalValue <= fence->signaledValue) { if (signalValue <= fence->signaledValue) {
fence->device->HandleError("Fence value less than or equal to signaled value"); fence->device->HandleError("Fence value less than or equal to signaled value");
return; return;
} }
fence->signaledValue = signalValue; 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) { void ClientDeviceReference(dawnDevice) {

View File

@ -18,38 +18,24 @@
namespace dawn_wire { namespace client { namespace dawn_wire { namespace client {
bool Client::HandleDeviceErrorCallback(const char** commands, size_t* size) { bool Client::DoDeviceErrorCallback(const char* message) {
ReturnDeviceErrorCallbackCmd cmd; DAWN_ASSERT(message != nullptr);
DeserializeResult deserializeResult = cmd.Deserialize(commands, size, &mAllocator); mDevice->HandleError(message);
if (deserializeResult == DeserializeResult::FatalError) {
return false;
}
DAWN_ASSERT(cmd.message != nullptr);
mDevice->HandleError(cmd.message);
return true; return true;
} }
bool Client::HandleBufferMapReadAsyncCallback(const char** commands, size_t* size) { bool Client::DoBufferMapReadAsyncCallback(Buffer* buffer,
ReturnBufferMapReadAsyncCallbackCmd cmd; uint32_t requestSerial,
DeserializeResult deserializeResult = cmd.Deserialize(commands, size, &mAllocator); uint32_t status,
uint32_t count,
if (deserializeResult == DeserializeResult::FatalError) { const uint8_t* data) {
return false;
}
auto* buffer = mDevice->GetClient()->BufferAllocator().GetObject(cmd.buffer.id);
uint32_t bufferSerial = mDevice->GetClient()->BufferAllocator().GetSerial(cmd.buffer.id);
// The buffer might have been deleted or recreated so this isn't an error. // 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; return true;
} }
// The requests can have been deleted via an Unmap so this isn't an error. // 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()) { if (requestIt == buffer->requests.end()) {
return true; 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 // On success, we copy the data locally because the IPC buffer isn't valid outside of this
// function // 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 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. // the application to crash if we did call the callback.
if (request.size != cmd.dataLength) { if (request.size != count) {
return false; return false;
} }
ASSERT(cmd.data != nullptr); ASSERT(data != nullptr);
if (buffer->mappedData != nullptr) { if (buffer->mappedData != nullptr) {
return false; return false;
@ -82,36 +68,28 @@ namespace dawn_wire { namespace client {
buffer->isWriteMapped = false; buffer->isWriteMapped = false;
buffer->mappedDataSize = request.size; buffer->mappedDataSize = request.size;
buffer->mappedData = malloc(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), request.readCallback(static_cast<dawnBufferMapAsyncStatus>(status), buffer->mappedData,
buffer->mappedData, request.userdata); request.userdata);
} else { } else {
request.readCallback(static_cast<dawnBufferMapAsyncStatus>(cmd.status), nullptr, request.readCallback(static_cast<dawnBufferMapAsyncStatus>(status), nullptr,
request.userdata); request.userdata);
} }
return true; return true;
} }
bool Client::HandleBufferMapWriteAsyncCallback(const char** commands, size_t* size) { bool Client::DoBufferMapWriteAsyncCallback(Buffer* buffer,
ReturnBufferMapWriteAsyncCallbackCmd cmd; uint32_t requestSerial,
DeserializeResult deserializeResult = cmd.Deserialize(commands, size, &mAllocator); uint32_t status) {
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);
// The buffer might have been deleted or recreated so this isn't an error. // 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; return true;
} }
// The requests can have been deleted via an Unmap so this isn't an error. // 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()) { if (requestIt == buffer->requests.end()) {
return true; 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 // On success, we copy the data locally because the IPC buffer isn't valid outside of this
// function // function
if (cmd.status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS) { if (status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS) {
if (buffer->mappedData != nullptr) { if (buffer->mappedData != nullptr) {
return false; return false;
} }
@ -138,33 +116,23 @@ namespace dawn_wire { namespace client {
buffer->mappedData = malloc(request.size); buffer->mappedData = malloc(request.size);
memset(buffer->mappedData, 0, request.size); memset(buffer->mappedData, 0, request.size);
request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(cmd.status), request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(status), buffer->mappedData,
buffer->mappedData, request.userdata); request.userdata);
} else { } else {
request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(cmd.status), nullptr, request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(status), nullptr,
request.userdata); request.userdata);
} }
return true; return true;
} }
bool Client::HandleFenceUpdateCompletedValue(const char** commands, size_t* size) { bool Client::DoFenceUpdateCompletedValue(Fence* fence, uint64_t value) {
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);
// The fence might have been deleted or recreated so this isn't an error. // 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; return true;
} }
fence->completedValue = cmd.value; fence->completedValue = value;
fence->CheckPassedFences(); fence->CheckPassedFences();
return true; return true;
} }