dawn_wire/server: Use MapAsync to do Map[Read/Write]Async

This changes the format of the client->server command for async mapping
to match MapAsync and updates the doer on the server to implement it via
MapAsync. Previously the command had an isWrite boolean that routed to
either MapReadAsync or MapWriteAsync.

Also updates the Wire tests using mock_webgpu.h for the new server-side
traces.

Bug: dawn:445

Change-Id: I673cbe5e08b7c71539e8678dbb07b4043a9fadb2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24820
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2020-07-16 17:07:05 +00:00 committed by Commit Bot service account
parent 2a232ba399
commit c15c6eb9d8
6 changed files with 186 additions and 219 deletions

View File

@ -14,11 +14,16 @@
"See the License for the specific language governing permissions and",
"limitations under the License."
],
"_todos": [
"Remove usage of size_t because it is not network transparent"
],
"commands": {
"buffer map async": [
{ "name": "buffer id", "type": "ObjectId" },
{ "name": "request serial", "type": "uint32_t" },
{ "name": "is write", "type": "bool" },
{ "name": "mode", "type": "map mode" },
{ "name": "offset", "type": "size_t"},
{ "name": "size", "type": "size_t"},
{ "name": "handle create info length", "type": "uint64_t" },
{ "name": "handle create info", "type": "uint8_t", "annotation": "const*", "length": "handle create info length", "skip_serialize": true}
],

View File

@ -21,7 +21,10 @@ namespace dawn_wire { namespace client {
namespace {
template <typename Handle>
void SerializeBufferMapAsync(const Buffer* buffer, uint32_t serial, Handle* handle) {
void SerializeBufferMapAsync(const Buffer* buffer,
uint32_t serial,
Handle* handle,
size_t size) {
// TODO(enga): Remove the template when Read/Write handles are combined in a tagged
// pointer.
constexpr bool isWrite =
@ -33,9 +36,11 @@ namespace dawn_wire { namespace client {
BufferMapAsyncCmd cmd;
cmd.bufferId = buffer->id;
cmd.requestSerial = serial;
cmd.isWrite = isWrite;
cmd.mode = isWrite ? WGPUMapMode_Write : WGPUMapMode_Read;
cmd.handleCreateInfoLength = handleCreateInfoLength;
cmd.handleCreateInfo = nullptr;
cmd.offset = 0;
cmd.size = size;
char* writeHandleSpace =
buffer->device->GetClient()->SerializeCommand(cmd, handleCreateInfoLength);
@ -200,7 +205,7 @@ namespace dawn_wire { namespace client {
// operations are returned by the server so multiple requests may be in flight.
mRequests[serial] = std::move(request);
SerializeBufferMapAsync(this, serial, readHandle);
SerializeBufferMapAsync(this, serial, readHandle, mSize);
}
void Buffer::MapWriteAsync(WGPUBufferMapWriteCallback callback, void* userdata) {
@ -236,7 +241,7 @@ namespace dawn_wire { namespace client {
// operations are returned by the server so multiple requests may be in flight.
mRequests[serial] = std::move(request);
SerializeBufferMapAsync(this, serial, writeHandle);
SerializeBufferMapAsync(this, serial, writeHandle, mSize);
}
void Buffer::MapAsync(WGPUMapModeFlags mode,

View File

@ -25,8 +25,10 @@ namespace dawn_wire { namespace server {
struct MapUserdata {
Server* server;
ObjectHandle buffer;
WGPUBuffer bufferObj;
uint32_t requestSerial;
uint64_t size;
WGPUMapModeFlags mode;
// TODO(enga): Use a tagged pointer to save space.
std::unique_ptr<MemoryTransferService::ReadHandle> readHandle = nullptr;
std::unique_ptr<MemoryTransferService::WriteHandle> writeHandle = nullptr;
@ -72,14 +74,7 @@ namespace dawn_wire { namespace server {
static void ForwardUncapturedError(WGPUErrorType type, const char* message, void* userdata);
static void ForwardDeviceLost(const char* message, void* userdata);
static void ForwardPopErrorScope(WGPUErrorType type, const char* message, void* userdata);
static void ForwardBufferMapReadAsync(WGPUBufferMapAsyncStatus status,
const void* ptr,
uint64_t dataLength,
void* userdata);
static void ForwardBufferMapWriteAsync(WGPUBufferMapAsyncStatus status,
void* ptr,
uint64_t dataLength,
void* userdata);
static void ForwardBufferMapAsync(WGPUBufferMapAsyncStatus status, void* userdata);
static void ForwardFenceCompletedValue(WGPUFenceCompletionStatus status, void* userdata);
// Error callbacks
@ -88,14 +83,7 @@ namespace dawn_wire { namespace server {
void OnDevicePopErrorScope(WGPUErrorType type,
const char* message,
ErrorScopeUserdata* userdata);
void OnBufferMapReadAsyncCallback(WGPUBufferMapAsyncStatus status,
const void* ptr,
uint64_t dataLength,
MapUserdata* userdata);
void OnBufferMapWriteAsyncCallback(WGPUBufferMapAsyncStatus status,
void* ptr,
uint64_t dataLength,
MapUserdata* userdata);
void OnBufferMapAsyncCallback(WGPUBufferMapAsyncStatus status, MapUserdata* userdata);
void OnFenceCompletedValueUpdated(WGPUFenceCompletionStatus status,
FenceCompletionUserdata* userdata);

View File

@ -46,7 +46,9 @@ namespace dawn_wire { namespace server {
bool Server::DoBufferMapAsync(ObjectId bufferId,
uint32_t requestSerial,
bool isWrite,
WGPUMapModeFlags mode,
size_t offset,
size_t size,
uint64_t handleCreateInfoLength,
const uint8_t* handleCreateInfo) {
// These requests are just forwarded to the buffer, with userdata containing what the
@ -62,6 +64,13 @@ namespace dawn_wire { namespace server {
return false;
}
// The server only knows how to deal with write XOR read. Validate that.
bool isReadMode = mode & WGPUMapMode_Read;
bool isWriteMode = mode & WGPUMapMode_Write;
if (!(isReadMode ^ isWriteMode)) {
return false;
}
if (handleCreateInfoLength > std::numeric_limits<size_t>::max()) {
// This is the size of data deserialized from the command stream, which must be
// CPU-addressable.
@ -71,11 +80,14 @@ namespace dawn_wire { namespace server {
std::unique_ptr<MapUserdata> userdata = std::make_unique<MapUserdata>();
userdata->server = this;
userdata->buffer = ObjectHandle{bufferId, buffer->generation};
userdata->bufferObj = buffer->handle;
userdata->requestSerial = requestSerial;
userdata->size = size;
userdata->mode = mode;
// The handle will point to the mapped memory or staging memory for the mapping.
// Store it on the map request.
if (isWrite) {
if (isWriteMode) {
// Deserialize metadata produced from the client to create a companion server handle.
MemoryTransferService::WriteHandle* writeHandle = nullptr;
if (!mMemoryTransferService->DeserializeWriteHandle(
@ -86,9 +98,8 @@ namespace dawn_wire { namespace server {
userdata->writeHandle =
std::unique_ptr<MemoryTransferService::WriteHandle>(writeHandle);
mProcs.bufferMapWriteAsync(buffer->handle, ForwardBufferMapWriteAsync,
userdata.release());
} else {
ASSERT(isReadMode);
// Deserialize metadata produced from the client to create a companion server handle.
MemoryTransferService::ReadHandle* readHandle = nullptr;
if (!mMemoryTransferService->DeserializeReadHandle(
@ -98,10 +109,11 @@ namespace dawn_wire { namespace server {
ASSERT(readHandle != nullptr);
userdata->readHandle = std::unique_ptr<MemoryTransferService::ReadHandle>(readHandle);
mProcs.bufferMapReadAsync(buffer->handle, ForwardBufferMapReadAsync,
userdata.release());
}
mProcs.bufferMapAsync(buffer->handle, mode, offset, size, ForwardBufferMapAsync,
userdata.release());
return true;
}
@ -209,65 +221,12 @@ namespace dawn_wire { namespace server {
static_cast<size_t>(writeFlushInfoLength));
}
void Server::ForwardBufferMapReadAsync(WGPUBufferMapAsyncStatus status,
const void* ptr,
uint64_t dataLength,
void* userdata) {
void Server::ForwardBufferMapAsync(WGPUBufferMapAsyncStatus status, void* userdata) {
auto data = static_cast<MapUserdata*>(userdata);
data->server->OnBufferMapReadAsyncCallback(status, ptr, dataLength, data);
data->server->OnBufferMapAsyncCallback(status, data);
}
void Server::ForwardBufferMapWriteAsync(WGPUBufferMapAsyncStatus status,
void* ptr,
uint64_t dataLength,
void* userdata) {
auto data = static_cast<MapUserdata*>(userdata);
data->server->OnBufferMapWriteAsyncCallback(status, ptr, dataLength, data);
}
void Server::OnBufferMapReadAsyncCallback(WGPUBufferMapAsyncStatus status,
const void* ptr,
uint64_t dataLength,
MapUserdata* userdata) {
std::unique_ptr<MapUserdata> data(userdata);
// Skip sending the callback if the buffer has already been destroyed.
auto* bufferData = BufferObjects().Get(data->buffer.id);
if (bufferData == nullptr || bufferData->generation != data->buffer.generation) {
return;
}
size_t initialDataInfoLength = 0;
if (status == WGPUBufferMapAsyncStatus_Success) {
// Get the serialization size of the message to initialize ReadHandle data.
initialDataInfoLength = data->readHandle->SerializeInitialDataSize(ptr, dataLength);
} else {
dataLength = 0;
}
ReturnBufferMapReadAsyncCallbackCmd cmd;
cmd.buffer = data->buffer;
cmd.requestSerial = data->requestSerial;
cmd.status = status;
cmd.initialDataInfoLength = initialDataInfoLength;
cmd.initialDataInfo = nullptr;
char* readHandleSpace = SerializeCommand(cmd, initialDataInfoLength);
if (status == WGPUBufferMapAsyncStatus_Success) {
// Serialize the initialization message into the space after the command.
data->readHandle->SerializeInitialData(ptr, dataLength, readHandleSpace);
// The in-flight map request returned successfully.
// Move the ReadHandle so it is owned by the buffer.
bufferData->readHandle = std::move(data->readHandle);
}
}
void Server::OnBufferMapWriteAsyncCallback(WGPUBufferMapAsyncStatus status,
void* ptr,
uint64_t dataLength,
MapUserdata* userdata) {
void Server::OnBufferMapAsyncCallback(WGPUBufferMapAsyncStatus status, MapUserdata* userdata) {
std::unique_ptr<MapUserdata> data(userdata);
// Skip sending the callback if the buffer has already been destroyed.
@ -276,6 +235,7 @@ namespace dawn_wire { namespace server {
return;
}
if (data->mode & WGPUMapMode_Write) {
ReturnBufferMapWriteAsyncCallbackCmd cmd;
cmd.buffer = data->buffer;
cmd.requestSerial = data->requestSerial;
@ -289,7 +249,41 @@ namespace dawn_wire { namespace server {
bufferData->writeHandle = std::move(data->writeHandle);
bufferData->mapWriteState = BufferMapWriteState::Mapped;
// Set the target of the WriteHandle to the mapped buffer data.
bufferData->writeHandle->SetTarget(ptr, dataLength);
bufferData->writeHandle->SetTarget(mProcs.bufferGetMappedRange(data->bufferObj),
data->size);
}
} else {
ASSERT(data->mode & WGPUMapMode_Read);
size_t initialDataInfoLength = 0;
size_t mappedDataLength = 0;
const void* mappedData = nullptr;
if (status == WGPUBufferMapAsyncStatus_Success) {
// Get the serialization size of the message to initialize ReadHandle data.
mappedDataLength = data->size;
mappedData = mProcs.bufferGetConstMappedRange(data->bufferObj);
initialDataInfoLength =
data->readHandle->SerializeInitialDataSize(mappedData, mappedDataLength);
}
ReturnBufferMapReadAsyncCallbackCmd cmd;
cmd.buffer = data->buffer;
cmd.requestSerial = data->requestSerial;
cmd.status = status;
cmd.initialDataInfoLength = initialDataInfoLength;
cmd.initialDataInfo = nullptr;
char* readHandleSpace = SerializeCommand(cmd, initialDataInfoLength);
if (status == WGPUBufferMapAsyncStatus_Success) {
// Serialize the initialization message into the space after the command.
data->readHandle->SerializeInitialData(mappedData, mappedDataLength,
readHandleSpace);
// The in-flight map request returned successfully.
// Move the ReadHandle so it is owned by the buffer.
bufferData->readHandle = std::move(data->readHandle);
}
}
}

View File

@ -125,11 +125,10 @@ TEST_F(WireBufferMappingTests, MappingForReadSuccessBuffer) {
wgpuBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &bufferContent,
kBufferSize);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetConstMappedRange(apiBuffer)).WillOnce(Return(&bufferContent));
FlushClient();
@ -150,9 +149,8 @@ TEST_F(WireBufferMappingTests, MappingForReadSuccessBuffer) {
TEST_F(WireBufferMappingTests, ErrorWhileMappingForRead) {
wgpuBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error, nullptr, 0);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error);
}));
FlushClient();
@ -169,10 +167,11 @@ TEST_F(WireBufferMappingTests, DestroyBeforeReadRequestEnd) {
wgpuBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
// Return success
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, nullptr, 0);
uint32_t bufferContent = 0;
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetConstMappedRange(apiBuffer)).WillOnce(Return(&bufferContent));
// Destroy before the client gets the success, so the callback is called with unknown.
EXPECT_CALL(*mockBufferMapReadCallback, Call(WGPUBufferMapAsyncStatus_Unknown, nullptr, 0, _))
@ -190,11 +189,10 @@ TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForRead) {
wgpuBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &bufferContent,
kBufferSize);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetConstMappedRange(apiBuffer)).WillOnce(Return(&bufferContent));
FlushClient();
@ -213,12 +211,10 @@ TEST_F(WireBufferMappingTests, MappingForReadingErrorWhileAlreadyMappedGetsNullp
wgpuBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &bufferContent,
kBufferSize);
}))
.RetiresOnSaturation();
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetConstMappedRange(apiBuffer)).WillOnce(Return(&bufferContent));
FlushClient();
@ -230,9 +226,8 @@ TEST_F(WireBufferMappingTests, MappingForReadingErrorWhileAlreadyMappedGetsNullp
// Map failure while the buffer is already mapped
wgpuBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error, nullptr, 0);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error);
}));
FlushClient();
@ -248,11 +243,10 @@ TEST_F(WireBufferMappingTests, UnmapInsideMapReadCallback) {
wgpuBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &bufferContent,
kBufferSize);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetConstMappedRange(apiBuffer)).WillOnce(Return(&bufferContent));
FlushClient();
@ -273,11 +267,10 @@ TEST_F(WireBufferMappingTests, DestroyInsideMapReadCallback) {
wgpuBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &bufferContent,
kBufferSize);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetConstMappedRange(apiBuffer)).WillOnce(Return(&bufferContent));
FlushClient();
@ -302,11 +295,10 @@ TEST_F(WireBufferMappingTests, MappingForWriteSuccessBuffer) {
uint32_t updatedContent = 4242;
uint32_t zero = 0;
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success,
&serverBufferContent, kBufferSize);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetMappedRange(apiBuffer)).WillOnce(Return(&serverBufferContent));
FlushClient();
@ -334,9 +326,8 @@ TEST_F(WireBufferMappingTests, MappingForWriteSuccessBuffer) {
TEST_F(WireBufferMappingTests, ErrorWhileMappingForWrite) {
wgpuBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, nullptr);
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error, nullptr, 0);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error);
}));
FlushClient();
@ -353,10 +344,11 @@ TEST_F(WireBufferMappingTests, DestroyBeforeWriteRequestEnd) {
wgpuBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, nullptr);
// Return success
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, nullptr, 0);
uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetMappedRange(apiBuffer)).WillOnce(Return(&bufferContent));
// Destroy before the client gets the success, so the callback is called with unknown.
EXPECT_CALL(*mockBufferMapWriteCallback, Call(WGPUBufferMapAsyncStatus_Unknown, nullptr, 0, _))
@ -374,11 +366,10 @@ TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForWrite) {
wgpuBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, nullptr);
uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &bufferContent,
kBufferSize);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetMappedRange(apiBuffer)).WillOnce(Return(&bufferContent));
FlushClient();
@ -398,12 +389,10 @@ TEST_F(WireBufferMappingTests, MappingForWritingErrorWhileAlreadyMappedGetsNullp
uint32_t bufferContent = 31337;
uint32_t zero = 0;
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &bufferContent,
kBufferSize);
}))
.RetiresOnSaturation();
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetMappedRange(apiBuffer)).WillOnce(Return(&bufferContent));
FlushClient();
@ -415,9 +404,8 @@ TEST_F(WireBufferMappingTests, MappingForWritingErrorWhileAlreadyMappedGetsNullp
// Map failure while the buffer is already mapped
wgpuBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, nullptr);
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error, nullptr, 0);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error);
}));
FlushClient();
@ -434,11 +422,10 @@ TEST_F(WireBufferMappingTests, UnmapInsideMapWriteCallback) {
uint32_t bufferContent = 31337;
uint32_t zero = 0;
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &bufferContent,
kBufferSize);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetMappedRange(apiBuffer)).WillOnce(Return(&bufferContent));
FlushClient();
@ -460,11 +447,10 @@ TEST_F(WireBufferMappingTests, DestroyInsideMapWriteCallback) {
uint32_t bufferContent = 31337;
uint32_t zero = 0;
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &bufferContent,
kBufferSize);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetMappedRange(apiBuffer)).WillOnce(Return(&bufferContent));
FlushClient();
@ -559,11 +545,10 @@ TEST_F(WireBufferMappingTests, CreateBufferMappedThenMapSuccess) {
wgpuBufferMapWriteAsync(result.buffer, ToMockBufferMapWriteCallback, nullptr);
uint32_t zero = 0;
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &apiBufferData,
kBufferSize);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetMappedRange(apiBuffer)).WillOnce(Return(&apiBufferData));
FlushClient();
@ -596,9 +581,8 @@ TEST_F(WireBufferMappingTests, CreateBufferMappedThenMapFailure) {
wgpuBufferMapWriteAsync(result.buffer, ToMockBufferMapWriteCallback, nullptr);
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error, nullptr, 0);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error);
}));
FlushClient();

View File

@ -386,11 +386,10 @@ TEST_F(WireMemoryTransferServiceTests, BufferMapReadSuccess) {
ExpectServerReadHandleInitialize(serverHandle);
// Mock a successful callback
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &mBufferContent,
sizeof(mBufferContent));
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetConstMappedRange(apiBuffer)).WillOnce(Return(&mBufferContent));
FlushClient();
@ -431,9 +430,8 @@ TEST_F(WireMemoryTransferServiceTests, BufferMapReadError) {
ServerReadHandle* serverHandle = ExpectServerReadHandleDeserialize();
// Mock a failed callback.
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error, nullptr, 0);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error);
}));
// Since the mapping failed, the handle is immediately destroyed.
@ -520,11 +518,10 @@ TEST_F(WireMemoryTransferServiceTests, BufferMapReadDeserializeInitialDataFailur
ExpectServerReadHandleInitialize(serverHandle);
// Mock a successful callback
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &mBufferContent,
sizeof(mBufferContent));
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetConstMappedRange(apiBuffer)).WillOnce(Return(&mBufferContent));
FlushClient();
@ -565,11 +562,10 @@ TEST_F(WireMemoryTransferServiceTests, BufferMapReadDestroyBeforeUnmap) {
ExpectServerReadHandleInitialize(serverHandle);
// Mock a successful callback
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success, &mBufferContent,
sizeof(mBufferContent));
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetConstMappedRange(apiBuffer)).WillOnce(Return(&mBufferContent));
FlushClient();
@ -617,11 +613,10 @@ TEST_F(WireMemoryTransferServiceTests, BufferMapWriteSuccess) {
ServerWriteHandle* serverHandle = ExpectServerWriteHandleDeserialization();
// Mock a successful callback.
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success,
&mMappedBufferContent, sizeof(mMappedBufferContent));
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetMappedRange(apiBuffer)).WillOnce(Return(&mMappedBufferContent));
FlushClient();
@ -672,9 +667,8 @@ TEST_F(WireMemoryTransferServiceTests, BufferMapWriteError) {
ServerWriteHandle* serverHandle = ExpectServerWriteHandleDeserialization();
// Mock an error callback.
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error, nullptr, 0);
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Error);
}));
// Since the mapping fails, the handle is immediately destroyed because it won't be written.
@ -758,11 +752,10 @@ TEST_F(WireMemoryTransferServiceTests, BufferMapWriteHandleOpenFailure) {
ServerWriteHandle* serverHandle = ExpectServerWriteHandleDeserialization();
// Mock a successful callback.
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success,
&mMappedBufferContent, sizeof(mMappedBufferContent));
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetMappedRange(apiBuffer)).WillOnce(Return(&mMappedBufferContent));
FlushClient();
@ -799,11 +792,10 @@ TEST_F(WireMemoryTransferServiceTests, BufferMapWriteDeserializeFlushFailure) {
ServerWriteHandle* serverHandle = ExpectServerWriteHandleDeserialization();
// Mock a successful callback.
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success,
&mMappedBufferContent, sizeof(mMappedBufferContent));
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetMappedRange(apiBuffer)).WillOnce(Return(&mMappedBufferContent));
FlushClient();
@ -851,11 +843,10 @@ TEST_F(WireMemoryTransferServiceTests, BufferMapWriteDestroyBeforeUnmap) {
ServerWriteHandle* serverHandle = ExpectServerWriteHandleDeserialization();
// Mock a successful callback.
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success,
&mMappedBufferContent, sizeof(mMappedBufferContent));
EXPECT_CALL(api, OnBufferMapAsyncCallback(apiBuffer, _, _)).WillOnce(InvokeWithoutArgs([&]() {
api.CallMapAsyncCallback(apiBuffer, WGPUBufferMapAsyncStatus_Success);
}));
EXPECT_CALL(api, BufferGetMappedRange(apiBuffer)).WillOnce(Return(&mMappedBufferContent));
FlushClient();