Replace dawn::CallbackUserdata with void*

This initial reasoning for having a u64 userdata was to be able to pack
two u32s in a single userdata but that was never used, and made a bunch
of code uglier than it should.

BUG=dawn:160

Change-Id: Ia0d20bc23f09f5d8f3748ca4edd1a331604f2ba8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/7561
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez 2019-05-29 13:03:50 +00:00 committed by Commit Bot service account
parent 26d3cf08c2
commit 839053b90c
35 changed files with 345 additions and 437 deletions

View File

@ -142,14 +142,14 @@
"name": "map read async", "name": "map read async",
"args": [ "args": [
{"name": "callback", "type": "buffer map read callback"}, {"name": "callback", "type": "buffer map read callback"},
{"name": "userdata", "type": "callback userdata"} {"name": "userdata", "type": "void", "annotation": "*"}
] ]
}, },
{ {
"name": "map write async", "name": "map write async",
"args": [ "args": [
{"name": "callback", "type": "buffer map write callback"}, {"name": "callback", "type": "buffer map write callback"},
{"name": "userdata", "type": "callback userdata"} {"name": "userdata", "type": "void", "annotation": "*"}
] ]
}, },
{ {
@ -207,9 +207,6 @@
{"value": 128, "name": "storage"} {"value": 128, "name": "storage"}
] ]
}, },
"callback userdata": {
"category": "natively defined"
},
"char": { "char": {
"category": "native" "category": "native"
}, },
@ -489,7 +486,7 @@
"name": "set error callback", "name": "set error callback",
"args": [ "args": [
{"name": "callback", "type": "device error callback"}, {"name": "callback", "type": "device error callback"},
{"name": "userdata", "type": "callback userdata"} {"name": "userdata", "type": "void", "annotation": "*"}
] ]
} }
] ]
@ -539,7 +536,7 @@
"args": [ "args": [
{"name": "value", "type": "uint64_t"}, {"name": "value", "type": "uint64_t"},
{"name": "callback", "type": "fence on completion callback"}, {"name": "callback", "type": "fence on completion callback"},
{"name": "userdata", "type": "callback userdata"} {"name": "userdata", "type": "void", "annotation": "*"}
] ]
} }
] ]

View File

@ -31,7 +31,7 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
void PrintDeviceError(const char* message, dawn::CallbackUserdata) { void PrintDeviceError(const char* message, void*) {
std::cout << "Device error: " << message << std::endl; std::cout << "Device error: " << message << std::endl;
} }
@ -136,7 +136,7 @@ dawn::Device CreateCppDawnDevice() {
} }
dawnSetProcs(&procs); dawnSetProcs(&procs);
procs.deviceSetErrorCallback(cDevice, PrintDeviceError, 0); procs.deviceSetErrorCallback(cDevice, PrintDeviceError, nullptr);
return dawn::Device::Acquire(cDevice); return dawn::Device::Acquire(cDevice);
} }

View File

@ -143,7 +143,7 @@ def linked_record_members(json_data, types):
for (member, m) in zip(members, json_data): for (member, m) in zip(members, json_data):
if member.annotation != 'value': if member.annotation != 'value':
if not 'length' in m: if not 'length' in m:
if member.type.category == 'structure': if member.type.category != 'object':
member.length = "constant" member.length = "constant"
member.constant_length = 1 member.constant_length = 1
else: else:

View File

@ -48,12 +48,16 @@
{% endfor %} {% endfor %}
// Custom types depending on the target language // Custom types depending on the target language
typedef uint64_t DawnCallbackUserdata; typedef void (*DawnDeviceErrorCallback)(const char* message, void* userdata);
typedef void (*DawnDeviceErrorCallback)(const char* message, DawnCallbackUserdata userdata); typedef void (*DawnBufferMapReadCallback)(DawnBufferMapAsyncStatus status,
typedef void (*DawnBufferMapReadCallback)(DawnBufferMapAsyncStatus status, const void* data, uint64_t dataLength, DawnCallbackUserdata userdata); const void* data,
typedef void (*DawnBufferMapWriteCallback)(DawnBufferMapAsyncStatus status, void* data, uint64_t dataLength, DawnCallbackUserdata userdata); uint64_t dataLength,
typedef void (*DawnFenceOnCompletionCallback)(DawnFenceCompletionStatus status, void* userdata);
DawnCallbackUserdata userdata); typedef void (*DawnBufferMapWriteCallback)(DawnBufferMapAsyncStatus status,
void* data,
uint64_t dataLength,
void* userdata);
typedef void (*DawnFenceOnCompletionCallback)(DawnFenceCompletionStatus status, void* userdata);
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -50,7 +50,9 @@ void ProcTableAsClass::GetProcTableAndDevice(DawnProcTable* table, DawnDevice* d
{% endfor %} {% endfor %}
} }
void ProcTableAsClass::DeviceSetErrorCallback(DawnDevice self, DawnDeviceErrorCallback callback, DawnCallbackUserdata userdata) { void ProcTableAsClass::DeviceSetErrorCallback(DawnDevice self,
DawnDeviceErrorCallback callback,
void* userdata) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self); auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
object->deviceErrorCallback = callback; object->deviceErrorCallback = callback;
object->userdata1 = userdata; object->userdata1 = userdata;
@ -58,7 +60,9 @@ void ProcTableAsClass::DeviceSetErrorCallback(DawnDevice self, DawnDeviceErrorCa
OnDeviceSetErrorCallback(self, callback, userdata); OnDeviceSetErrorCallback(self, callback, userdata);
} }
void ProcTableAsClass::BufferMapReadAsync(DawnBuffer self, DawnBufferMapReadCallback callback, DawnCallbackUserdata userdata) { void ProcTableAsClass::BufferMapReadAsync(DawnBuffer self,
DawnBufferMapReadCallback callback,
void* userdata) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self); auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
object->mapReadCallback = callback; object->mapReadCallback = callback;
object->userdata1 = userdata; object->userdata1 = userdata;
@ -66,7 +70,9 @@ void ProcTableAsClass::BufferMapReadAsync(DawnBuffer self, DawnBufferMapReadCall
OnBufferMapReadAsyncCallback(self, callback, userdata); OnBufferMapReadAsyncCallback(self, callback, userdata);
} }
void ProcTableAsClass::BufferMapWriteAsync(DawnBuffer self, DawnBufferMapWriteCallback callback, DawnCallbackUserdata userdata) { void ProcTableAsClass::BufferMapWriteAsync(DawnBuffer self,
DawnBufferMapWriteCallback callback,
void* userdata) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self); auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
object->mapWriteCallback = callback; object->mapWriteCallback = callback;
object->userdata1 = userdata; object->userdata1 = userdata;
@ -77,7 +83,7 @@ void ProcTableAsClass::BufferMapWriteAsync(DawnBuffer self, DawnBufferMapWriteCa
void ProcTableAsClass::FenceOnCompletion(DawnFence self, void ProcTableAsClass::FenceOnCompletion(DawnFence self,
uint64_t value, uint64_t value,
DawnFenceOnCompletionCallback callback, DawnFenceOnCompletionCallback callback,
DawnCallbackUserdata userdata) { void* userdata) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self); auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
object->fenceOnCompletionCallback = callback; object->fenceOnCompletionCallback = callback;
object->userdata1 = userdata; object->userdata1 = userdata;

View File

@ -51,22 +51,34 @@ class ProcTableAsClass {
{% endfor %} {% endfor %}
// Stores callback and userdata and calls the On* methods // Stores callback and userdata and calls the On* methods
void DeviceSetErrorCallback(DawnDevice self, DawnDeviceErrorCallback callback, DawnCallbackUserdata userdata); void DeviceSetErrorCallback(DawnDevice self,
void BufferMapReadAsync(DawnBuffer self, DawnBufferMapReadCallback callback, DawnCallbackUserdata userdata); DawnDeviceErrorCallback callback,
void BufferMapWriteAsync(DawnBuffer self, DawnBufferMapWriteCallback callback, DawnCallbackUserdata userdata); void* userdata);
void BufferMapReadAsync(DawnBuffer self,
DawnBufferMapReadCallback callback,
void* userdata);
void BufferMapWriteAsync(DawnBuffer self,
DawnBufferMapWriteCallback callback,
void* userdata);
void FenceOnCompletion(DawnFence self, void FenceOnCompletion(DawnFence self,
uint64_t value, uint64_t value,
DawnFenceOnCompletionCallback callback, DawnFenceOnCompletionCallback callback,
DawnCallbackUserdata userdata); void* userdata);
// Special cased mockable methods // Special cased mockable methods
virtual void OnDeviceSetErrorCallback(DawnDevice device, DawnDeviceErrorCallback callback, DawnCallbackUserdata userdata) = 0; virtual void OnDeviceSetErrorCallback(DawnDevice device,
virtual void OnBufferMapReadAsyncCallback(DawnBuffer buffer, DawnBufferMapReadCallback callback, DawnCallbackUserdata userdata) = 0; DawnDeviceErrorCallback callback,
virtual void OnBufferMapWriteAsyncCallback(DawnBuffer buffer, DawnBufferMapWriteCallback callback, DawnCallbackUserdata userdata) = 0; void* userdata) = 0;
virtual void OnBufferMapReadAsyncCallback(DawnBuffer buffer,
DawnBufferMapReadCallback callback,
void* userdata) = 0;
virtual void OnBufferMapWriteAsyncCallback(DawnBuffer buffer,
DawnBufferMapWriteCallback callback,
void* userdata) = 0;
virtual void OnFenceOnCompletionCallback(DawnFence fence, virtual void OnFenceOnCompletionCallback(DawnFence fence,
uint64_t value, uint64_t value,
DawnFenceOnCompletionCallback callback, DawnFenceOnCompletionCallback callback,
DawnCallbackUserdata userdata) = 0; void* userdata) = 0;
// Calls the stored callbacks // Calls the stored callbacks
void CallDeviceErrorCallback(DawnDevice device, const char* message); void CallDeviceErrorCallback(DawnDevice device, const char* message);
@ -80,8 +92,8 @@ class ProcTableAsClass {
DawnBufferMapReadCallback mapReadCallback = nullptr; DawnBufferMapReadCallback mapReadCallback = nullptr;
DawnBufferMapWriteCallback mapWriteCallback = nullptr; DawnBufferMapWriteCallback mapWriteCallback = nullptr;
DawnFenceOnCompletionCallback fenceOnCompletionCallback = nullptr; DawnFenceOnCompletionCallback fenceOnCompletionCallback = nullptr;
DawnCallbackUserdata userdata1 = 0; void* userdata1 = 0;
DawnCallbackUserdata userdata2 = 0; void* userdata2 = 0;
}; };
private: private:
@ -111,14 +123,14 @@ class MockProcTable : public ProcTableAsClass {
MOCK_METHOD1({{as_MethodSuffix(type.name, Name("release"))}}, void({{as_cType(type.name)}} self)); MOCK_METHOD1({{as_MethodSuffix(type.name, Name("release"))}}, void({{as_cType(type.name)}} self));
{% endfor %} {% endfor %}
MOCK_METHOD3(OnDeviceSetErrorCallback, void(DawnDevice device, DawnDeviceErrorCallback callback, DawnCallbackUserdata userdata)); MOCK_METHOD3(OnDeviceSetErrorCallback, void(DawnDevice device, DawnDeviceErrorCallback callback, void* userdata));
MOCK_METHOD3(OnBufferMapReadAsyncCallback, void(DawnBuffer buffer, DawnBufferMapReadCallback callback, DawnCallbackUserdata userdata)); MOCK_METHOD3(OnBufferMapReadAsyncCallback, void(DawnBuffer buffer, DawnBufferMapReadCallback callback, void* userdata));
MOCK_METHOD3(OnBufferMapWriteAsyncCallback, void(DawnBuffer buffer, DawnBufferMapWriteCallback callback, DawnCallbackUserdata userdata)); MOCK_METHOD3(OnBufferMapWriteAsyncCallback, void(DawnBuffer buffer, DawnBufferMapWriteCallback callback, void* userdata));
MOCK_METHOD4(OnFenceOnCompletionCallback, MOCK_METHOD4(OnFenceOnCompletionCallback,
void(DawnFence fence, void(DawnFence fence,
uint64_t value, uint64_t value,
DawnFenceOnCompletionCallback callback, DawnFenceOnCompletionCallback callback,
DawnCallbackUserdata userdata)); void* userdata));
}; };
#endif // MOCK_DAWN_H #endif // MOCK_DAWN_H

View File

@ -211,8 +211,7 @@ namespace dawn_native {
} }
} }
void BufferBase::MapReadAsync(DawnBufferMapReadCallback callback, void BufferBase::MapReadAsync(DawnBufferMapReadCallback callback, void* userdata) {
DawnCallbackUserdata userdata) {
if (GetDevice()->ConsumedError(ValidateMap(dawn::BufferUsageBit::MapRead))) { if (GetDevice()->ConsumedError(ValidateMap(dawn::BufferUsageBit::MapRead))) {
callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata); callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata);
return; return;
@ -250,8 +249,7 @@ namespace dawn_native {
return {}; return {};
} }
void BufferBase::MapWriteAsync(DawnBufferMapWriteCallback callback, void BufferBase::MapWriteAsync(DawnBufferMapWriteCallback callback, void* userdata) {
DawnCallbackUserdata userdata) {
if (GetDevice()->ConsumedError(ValidateMap(dawn::BufferUsageBit::MapWrite))) { if (GetDevice()->ConsumedError(ValidateMap(dawn::BufferUsageBit::MapWrite))) {
callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata); callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata);
return; return;

View File

@ -58,8 +58,8 @@ namespace dawn_native {
// Dawn API // Dawn API
void SetSubData(uint32_t start, uint32_t count, const uint8_t* data); void SetSubData(uint32_t start, uint32_t count, const uint8_t* data);
void MapReadAsync(DawnBufferMapReadCallback callback, DawnCallbackUserdata userdata); void MapReadAsync(DawnBufferMapReadCallback callback, void* userdata);
void MapWriteAsync(DawnBufferMapWriteCallback callback, DawnCallbackUserdata userdata); void MapWriteAsync(DawnBufferMapWriteCallback callback, void* userdata);
void Unmap(); void Unmap();
void Destroy(); void Destroy();
@ -95,7 +95,7 @@ namespace dawn_native {
DawnBufferMapReadCallback mMapReadCallback = nullptr; DawnBufferMapReadCallback mMapReadCallback = nullptr;
DawnBufferMapWriteCallback mMapWriteCallback = nullptr; DawnBufferMapWriteCallback mMapWriteCallback = nullptr;
DawnCallbackUserdata mMapUserdata = 0; void* mMapUserdata = 0;
uint32_t mMapSerial = 0; uint32_t mMapSerial = 0;
BufferState mState; BufferState mState;

View File

@ -75,8 +75,7 @@ namespace dawn_native {
} }
} }
void DeviceBase::SetErrorCallback(dawn::DeviceErrorCallback callback, void DeviceBase::SetErrorCallback(dawn::DeviceErrorCallback callback, void* userdata) {
dawn::CallbackUserdata userdata) {
mErrorCallback = callback; mErrorCallback = callback;
mErrorUserdata = userdata; mErrorUserdata = userdata;
} }

View File

@ -122,7 +122,7 @@ namespace dawn_native {
void Tick(); void Tick();
void SetErrorCallback(dawn::DeviceErrorCallback callback, dawn::CallbackUserdata userdata); void SetErrorCallback(dawn::DeviceErrorCallback callback, void* userdata);
void Reference(); void Reference();
void Release(); void Release();
@ -204,7 +204,7 @@ namespace dawn_native {
std::unique_ptr<FenceSignalTracker> mFenceSignalTracker; std::unique_ptr<FenceSignalTracker> mFenceSignalTracker;
dawn::DeviceErrorCallback mErrorCallback = nullptr; dawn::DeviceErrorCallback mErrorCallback = nullptr;
dawn::CallbackUserdata mErrorUserdata = 0; void* mErrorUserdata = 0;
uint32_t mRefCount = 1; uint32_t mRefCount = 1;
TogglesSet mTogglesSet; TogglesSet mTogglesSet;

View File

@ -65,7 +65,7 @@ namespace dawn_native {
void FenceBase::OnCompletion(uint64_t value, void FenceBase::OnCompletion(uint64_t value,
dawn::FenceOnCompletionCallback callback, dawn::FenceOnCompletionCallback callback,
dawn::CallbackUserdata userdata) { void* userdata) {
if (GetDevice()->ConsumedError(ValidateOnCompletion(value))) { if (GetDevice()->ConsumedError(ValidateOnCompletion(value))) {
callback(DAWN_FENCE_COMPLETION_STATUS_ERROR, userdata); callback(DAWN_FENCE_COMPLETION_STATUS_ERROR, userdata);
return; return;

View File

@ -40,9 +40,7 @@ namespace dawn_native {
// Dawn API // Dawn API
uint64_t GetCompletedValue() const; uint64_t GetCompletedValue() const;
void OnCompletion(uint64_t value, void OnCompletion(uint64_t value, dawn::FenceOnCompletionCallback callback, void* userdata);
dawn::FenceOnCompletionCallback callback,
dawn::CallbackUserdata userdata);
protected: protected:
friend class QueueBase; friend class QueueBase;
@ -57,7 +55,7 @@ namespace dawn_native {
struct OnCompletionData { struct OnCompletionData {
dawn::FenceOnCompletionCallback completionCallback = nullptr; dawn::FenceOnCompletionCallback completionCallback = nullptr;
dawn::CallbackUserdata userdata = 0; void* userdata = nullptr;
}; };
uint64_t mSignalValue; uint64_t mSignalValue;

View File

@ -20,7 +20,7 @@ namespace dawn_wire { namespace client {
void ClientBufferMapReadAsync(DawnBuffer cBuffer, void ClientBufferMapReadAsync(DawnBuffer cBuffer,
DawnBufferMapReadCallback callback, DawnBufferMapReadCallback callback,
DawnCallbackUserdata userdata) { void* userdata) {
Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer); Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer);
uint32_t serial = buffer->requestSerial++; uint32_t serial = buffer->requestSerial++;
@ -45,7 +45,7 @@ namespace dawn_wire { namespace client {
void ClientBufferMapWriteAsync(DawnBuffer cBuffer, void ClientBufferMapWriteAsync(DawnBuffer cBuffer,
DawnBufferMapWriteCallback callback, DawnBufferMapWriteCallback callback,
DawnCallbackUserdata userdata) { void* userdata) {
Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer); Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer);
uint32_t serial = buffer->requestSerial++; uint32_t serial = buffer->requestSerial++;
@ -109,7 +109,7 @@ namespace dawn_wire { namespace client {
void ClientFenceOnCompletion(DawnFence cFence, void ClientFenceOnCompletion(DawnFence cFence,
uint64_t value, uint64_t value,
DawnFenceOnCompletionCallback callback, DawnFenceOnCompletionCallback callback,
DawnCallbackUserdata userdata) { void* userdata) {
Fence* fence = reinterpret_cast<Fence*>(cFence); Fence* fence = reinterpret_cast<Fence*>(cFence);
if (value > fence->signaledValue) { if (value > fence->signaledValue) {
fence->device->HandleError("Value greater than fence signaled value"); fence->device->HandleError("Value greater than fence signaled value");
@ -222,7 +222,7 @@ namespace dawn_wire { namespace client {
void ClientDeviceSetErrorCallback(DawnDevice cSelf, void ClientDeviceSetErrorCallback(DawnDevice cSelf,
DawnDeviceErrorCallback callback, DawnDeviceErrorCallback callback,
DawnCallbackUserdata userdata) { void* userdata) {
Device* device = reinterpret_cast<Device*>(cSelf); Device* device = reinterpret_cast<Device*>(cSelf);
device->SetErrorCallback(callback, userdata); device->SetErrorCallback(callback, userdata);
} }

View File

@ -35,7 +35,7 @@ namespace dawn_wire { namespace client {
struct MapRequestData { struct MapRequestData {
DawnBufferMapReadCallback readCallback = nullptr; DawnBufferMapReadCallback readCallback = nullptr;
DawnBufferMapWriteCallback writeCallback = nullptr; DawnBufferMapWriteCallback writeCallback = nullptr;
DawnCallbackUserdata userdata = 0; void* userdata = nullptr;
bool isWrite = false; bool isWrite = false;
}; };
std::map<uint32_t, MapRequestData> requests; std::map<uint32_t, MapRequestData> requests;

View File

@ -31,8 +31,7 @@ namespace dawn_wire { namespace client {
} }
} }
void Device::SetErrorCallback(DawnDeviceErrorCallback errorCallback, void Device::SetErrorCallback(DawnDeviceErrorCallback errorCallback, void* errorUserdata) {
DawnCallbackUserdata errorUserdata) {
mErrorCallback = errorCallback; mErrorCallback = errorCallback;
mErrorUserdata = errorUserdata; mErrorUserdata = errorUserdata;
} }

View File

@ -29,13 +29,12 @@ namespace dawn_wire { namespace client {
Client* GetClient(); Client* GetClient();
void HandleError(const char* message); void HandleError(const char* message);
void SetErrorCallback(DawnDeviceErrorCallback errorCallback, void SetErrorCallback(DawnDeviceErrorCallback errorCallback, void* errorUserdata);
DawnCallbackUserdata errorUserdata);
private: private:
Client* mClient = nullptr; Client* mClient = nullptr;
DawnDeviceErrorCallback mErrorCallback = nullptr; DawnDeviceErrorCallback mErrorCallback = nullptr;
DawnCallbackUserdata mErrorUserdata; void* mErrorUserdata;
}; };
}} // namespace dawn_wire::client }} // namespace dawn_wire::client

View File

@ -31,7 +31,7 @@ namespace dawn_wire { namespace client {
struct OnCompletionData { struct OnCompletionData {
DawnFenceOnCompletionCallback completionCallback = nullptr; DawnFenceOnCompletionCallback completionCallback = nullptr;
DawnCallbackUserdata userdata = 0; void* userdata = nullptr;
}; };
Queue* queue = nullptr; Queue* queue = nullptr;
uint64_t signaledValue = 0; uint64_t signaledValue = 0;

View File

@ -22,8 +22,7 @@ namespace dawn_wire { namespace server {
auto* deviceData = DeviceObjects().Allocate(1); auto* deviceData = DeviceObjects().Allocate(1);
deviceData->handle = device; deviceData->handle = device;
auto userdata = static_cast<DawnCallbackUserdata>(reinterpret_cast<intptr_t>(this)); mProcs.deviceSetErrorCallback(device, ForwardDeviceError, this);
mProcs.deviceSetErrorCallback(device, ForwardDeviceError, userdata);
} }
Server::~Server() { Server::~Server() {

View File

@ -48,17 +48,16 @@ namespace dawn_wire { namespace server {
void* GetCmdSpace(size_t size); void* GetCmdSpace(size_t size);
// Forwarding callbacks // Forwarding callbacks
static void ForwardDeviceError(const char* message, DawnCallbackUserdata userdata); static void ForwardDeviceError(const char* message, void* userdata);
static void ForwardBufferMapReadAsync(DawnBufferMapAsyncStatus status, static void ForwardBufferMapReadAsync(DawnBufferMapAsyncStatus status,
const void* ptr, const void* ptr,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata); void* userdata);
static void ForwardBufferMapWriteAsync(DawnBufferMapAsyncStatus status, static void ForwardBufferMapWriteAsync(DawnBufferMapAsyncStatus status,
void* ptr, void* ptr,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata); void* userdata);
static void ForwardFenceCompletedValue(DawnFenceCompletionStatus status, static void ForwardFenceCompletedValue(DawnFenceCompletionStatus status, void* userdata);
DawnCallbackUserdata userdata);
// Error callbacks // Error callbacks
void OnDeviceError(const char* message); void OnDeviceError(const char* message);

View File

@ -44,13 +44,11 @@ namespace dawn_wire { namespace server {
return false; return false;
} }
auto* data = new MapUserdata; MapUserdata* userdata = new MapUserdata;
data->server = this; userdata->server = this;
data->buffer = ObjectHandle{bufferId, buffer->serial}; userdata->buffer = ObjectHandle{bufferId, buffer->serial};
data->requestSerial = requestSerial; userdata->requestSerial = requestSerial;
data->isWrite = isWrite; userdata->isWrite = isWrite;
auto userdata = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(data));
if (isWrite) { if (isWrite) {
mProcs.bufferMapWriteAsync(buffer->handle, ForwardBufferMapWriteAsync, userdata); mProcs.bufferMapWriteAsync(buffer->handle, ForwardBufferMapWriteAsync, userdata);
@ -103,16 +101,16 @@ namespace dawn_wire { namespace server {
void Server::ForwardBufferMapReadAsync(DawnBufferMapAsyncStatus status, void Server::ForwardBufferMapReadAsync(DawnBufferMapAsyncStatus status,
const void* ptr, const void* ptr,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata) { void* userdata) {
auto data = reinterpret_cast<MapUserdata*>(static_cast<uintptr_t>(userdata)); auto data = static_cast<MapUserdata*>(userdata);
data->server->OnBufferMapReadAsyncCallback(status, ptr, dataLength, data); data->server->OnBufferMapReadAsyncCallback(status, ptr, dataLength, data);
} }
void Server::ForwardBufferMapWriteAsync(DawnBufferMapAsyncStatus status, void Server::ForwardBufferMapWriteAsync(DawnBufferMapAsyncStatus status,
void* ptr, void* ptr,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata) { void* userdata) {
auto data = reinterpret_cast<MapUserdata*>(static_cast<uintptr_t>(userdata)); auto data = static_cast<MapUserdata*>(userdata);
data->server->OnBufferMapWriteAsyncCallback(status, ptr, dataLength, data); data->server->OnBufferMapWriteAsyncCallback(status, ptr, dataLength, data);
} }

View File

@ -16,8 +16,8 @@
namespace dawn_wire { namespace server { namespace dawn_wire { namespace server {
void Server::ForwardDeviceError(const char* message, DawnCallbackUserdata userdata) { void Server::ForwardDeviceError(const char* message, void* userdata) {
auto server = reinterpret_cast<Server*>(static_cast<intptr_t>(userdata)); auto server = static_cast<Server*>(userdata);
server->OnDeviceError(message); server->OnDeviceError(message);
} }

View File

@ -18,9 +18,8 @@
namespace dawn_wire { namespace server { namespace dawn_wire { namespace server {
void Server::ForwardFenceCompletedValue(DawnFenceCompletionStatus status, void Server::ForwardFenceCompletedValue(DawnFenceCompletionStatus status, void* userdata) {
DawnCallbackUserdata userdata) { auto data = static_cast<FenceCompletionUserdata*>(userdata);
auto data = reinterpret_cast<FenceCompletionUserdata*>(static_cast<uintptr_t>(userdata));
data->server->OnFenceCompletedValueUpdated(status, data); data->server->OnFenceCompletedValueUpdated(status, data);
} }

View File

@ -29,12 +29,11 @@ namespace dawn_wire { namespace server {
auto* fence = FenceObjects().Get(fenceId); auto* fence = FenceObjects().Get(fenceId);
ASSERT(fence != nullptr); ASSERT(fence != nullptr);
auto* data = new FenceCompletionUserdata; FenceCompletionUserdata* userdata = new FenceCompletionUserdata;
data->server = this; userdata->server = this;
data->fence = ObjectHandle{fenceId, fence->serial}; userdata->fence = ObjectHandle{fenceId, fence->serial};
data->value = signalValue; userdata->value = signalValue;
auto userdata = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(data));
mProcs.fenceOnCompletion(cFence, signalValue, ForwardFenceCompletedValue, userdata); mProcs.fenceOnCompletion(cFence, signalValue, ForwardFenceCompletedValue, userdata);
return true; return true;
} }

View File

@ -361,8 +361,7 @@ void DawnTest::SetUp() {
static_cast<dawn::TextureFormat>(mBinding->GetPreferredSwapChainTextureFormat()), static_cast<dawn::TextureFormat>(mBinding->GetPreferredSwapChainTextureFormat()),
dawn::TextureUsageBit::OutputAttachment, 400, 400); dawn::TextureUsageBit::OutputAttachment, 400, 400);
device.SetErrorCallback(OnDeviceError, device.SetErrorCallback(OnDeviceError, this);
static_cast<DawnCallbackUserdata>(reinterpret_cast<uintptr_t>(this)));
} }
void DawnTest::TearDown() { void DawnTest::TearDown() {
@ -387,8 +386,8 @@ bool DawnTest::EndExpectDeviceError() {
} }
// static // static
void DawnTest::OnDeviceError(const char* message, DawnCallbackUserdata userdata) { void DawnTest::OnDeviceError(const char* message, void* userdata) {
DawnTest* self = reinterpret_cast<DawnTest*>(static_cast<uintptr_t>(userdata)); DawnTest* self = static_cast<DawnTest*>(userdata);
ASSERT_TRUE(self->mExpectError) << "Got unexpected device error: " << message; ASSERT_TRUE(self->mExpectError) << "Got unexpected device error: " << message;
ASSERT_FALSE(self->mError) << "Got two errors in expect block"; ASSERT_FALSE(self->mError) << "Got two errors in expect block";
@ -520,11 +519,10 @@ void DawnTest::MapSlotsSynchronously() {
// Map all readback slots // Map all readback slots
for (size_t i = 0; i < mReadbackSlots.size(); ++i) { for (size_t i = 0; i < mReadbackSlots.size(); ++i) {
auto userdata = new MapReadUserdata{this, i}; MapReadUserdata* userdata = new MapReadUserdata{this, i};
auto& slot = mReadbackSlots[i]; auto& slot = mReadbackSlots[i];
slot.buffer.MapReadAsync(SlotMapReadCallback, static_cast<dawn::CallbackUserdata>( slot.buffer.MapReadAsync(SlotMapReadCallback, userdata);
reinterpret_cast<uintptr_t>(userdata)));
} }
// Busy wait until all map operations are done. // Busy wait until all map operations are done.
@ -537,10 +535,10 @@ void DawnTest::MapSlotsSynchronously() {
void DawnTest::SlotMapReadCallback(DawnBufferMapAsyncStatus status, void DawnTest::SlotMapReadCallback(DawnBufferMapAsyncStatus status,
const void* data, const void* data,
uint64_t, uint64_t,
DawnCallbackUserdata userdata_) { void* userdata_) {
DAWN_ASSERT(status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS); DAWN_ASSERT(status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS);
auto userdata = reinterpret_cast<MapReadUserdata*>(static_cast<uintptr_t>(userdata_)); auto userdata = static_cast<MapReadUserdata*>(userdata_);
userdata->test->mReadbackSlots[userdata->slot].mappedData = data; userdata->test->mReadbackSlots[userdata->slot].mappedData = data;
userdata->test->mNumPendingMapOperations--; userdata->test->mNumPendingMapOperations--;

View File

@ -192,7 +192,7 @@ class DawnTest : public ::testing::TestWithParam<DawnTestParam> {
std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf; std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf;
// Tracking for validation errors // Tracking for validation errors
static void OnDeviceError(const char* message, DawnCallbackUserdata userdata); static void OnDeviceError(const char* message, void* userdata);
bool mExpectError = false; bool mExpectError = false;
bool mError = false; bool mError = false;
@ -209,7 +209,7 @@ class DawnTest : public ::testing::TestWithParam<DawnTestParam> {
static void SlotMapReadCallback(DawnBufferMapAsyncStatus status, static void SlotMapReadCallback(DawnBufferMapAsyncStatus status,
const void* data, const void* data,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata); void* userdata);
size_t mNumPendingMapOperations = 0; size_t mNumPendingMapOperations = 0;
// Reserve space where the data for an expectation can be copied // Reserve space where the data for an expectation can be copied

View File

@ -21,17 +21,15 @@ class BufferMapReadTests : public DawnTest {
static void MapReadCallback(DawnBufferMapAsyncStatus status, static void MapReadCallback(DawnBufferMapAsyncStatus status,
const void* data, const void* data,
uint64_t, uint64_t,
DawnCallbackUserdata userdata) { void* userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status); ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status);
ASSERT_NE(nullptr, data); ASSERT_NE(nullptr, data);
auto test = reinterpret_cast<BufferMapReadTests*>(static_cast<uintptr_t>(userdata)); static_cast<BufferMapReadTests*>(userdata)->mappedData = data;
test->mappedData = data;
} }
const void* MapReadAsyncAndWait(const dawn::Buffer& buffer) { const void* MapReadAsyncAndWait(const dawn::Buffer& buffer) {
buffer.MapReadAsync(MapReadCallback, static_cast<dawn::CallbackUserdata>( buffer.MapReadAsync(MapReadCallback, this);
reinterpret_cast<uintptr_t>(this)));
while (mappedData == nullptr) { while (mappedData == nullptr) {
WaitABit(); WaitABit();
@ -88,17 +86,15 @@ class BufferMapWriteTests : public DawnTest {
static void MapWriteCallback(DawnBufferMapAsyncStatus status, static void MapWriteCallback(DawnBufferMapAsyncStatus status,
void* data, void* data,
uint64_t, uint64_t,
DawnCallbackUserdata userdata) { void* userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status); ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status);
ASSERT_NE(nullptr, data); ASSERT_NE(nullptr, data);
auto test = reinterpret_cast<BufferMapWriteTests*>(static_cast<uintptr_t>(userdata)); static_cast<BufferMapWriteTests*>(userdata)->mappedData = data;
test->mappedData = data;
} }
void* MapWriteAsyncAndWait(const dawn::Buffer& buffer) { void* MapWriteAsyncAndWait(const dawn::Buffer& buffer) {
buffer.MapWriteAsync(MapWriteCallback, static_cast<dawn::CallbackUserdata>( buffer.MapWriteAsync(MapWriteCallback, this);
reinterpret_cast<uintptr_t>(this)));
while (mappedData == nullptr) { while (mappedData == nullptr) {
WaitABit(); WaitABit();
@ -301,14 +297,14 @@ TEST_P(CreateBufferMappedTests, CreateThenMapSuccess) {
bool done = false; bool done = false;
result.buffer.MapWriteAsync( result.buffer.MapWriteAsync(
[](DawnBufferMapAsyncStatus status, void* data, uint64_t, DawnCallbackUserdata userdata) { [](DawnBufferMapAsyncStatus status, void* data, uint64_t, void* userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status); ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status);
ASSERT_NE(nullptr, data); ASSERT_NE(nullptr, data);
*reinterpret_cast<uint32_t*>(data) = myData2; *static_cast<uint32_t*>(data) = myData2;
*reinterpret_cast<bool*>(static_cast<uintptr_t>(userdata)) = true; *static_cast<bool*>(userdata) = true;
}, },
static_cast<DawnCallbackUserdata>(reinterpret_cast<uintptr_t>(&done))); &done);
while (!done) { while (!done) {
WaitABit(); WaitABit();
@ -333,14 +329,13 @@ TEST_P(CreateBufferMappedTests, CreateThenMapBeforeUnmapFailure) {
ASSERT_DEVICE_ERROR([&]() { ASSERT_DEVICE_ERROR([&]() {
bool done = false; bool done = false;
result.buffer.MapWriteAsync( result.buffer.MapWriteAsync(
[](DawnBufferMapAsyncStatus status, void* data, uint64_t, [](DawnBufferMapAsyncStatus status, void* data, uint64_t, void* userdata) {
DawnCallbackUserdata userdata) {
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, status); ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, status);
ASSERT_EQ(nullptr, data); ASSERT_EQ(nullptr, data);
*reinterpret_cast<bool*>(static_cast<uintptr_t>(userdata)) = true; *static_cast<bool*>(userdata) = true;
}, },
static_cast<DawnCallbackUserdata>(reinterpret_cast<uintptr_t>(&done))); &done);
while (!done) { while (!done) {
WaitABit(); WaitABit();

View File

@ -20,12 +20,11 @@
class MockFenceOnCompletionCallback { class MockFenceOnCompletionCallback {
public: public:
MOCK_METHOD2(Call, void(DawnFenceCompletionStatus status, DawnCallbackUserdata userdata)); MOCK_METHOD2(Call, void(DawnFenceCompletionStatus status, void* userdata));
}; };
static std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback; static std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback;
static void ToMockFenceOnCompletionCallback(DawnFenceCompletionStatus status, static void ToMockFenceOnCompletionCallback(DawnFenceCompletionStatus status, void* userdata) {
DawnCallbackUserdata userdata) {
mockFenceOnCompletionCallback->Call(status, userdata); mockFenceOnCompletionCallback->Call(status, userdata);
} }
class FenceTests : public DawnTest { class FenceTests : public DawnTest {
@ -89,35 +88,30 @@ TEST_P(FenceTests, OnCompletionOrdering) {
queue.Signal(fence, 4); queue.Signal(fence, 4);
DawnCallbackUserdata userdata0 = 1282;
DawnCallbackUserdata userdata1 = 4382;
DawnCallbackUserdata userdata2 = 1211;
DawnCallbackUserdata userdata3 = 1882;
{ {
testing::InSequence s; testing::InSequence s;
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata0)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 0))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata1)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 1))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata2)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 2))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata3)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 3))
.Times(1); .Times(1);
} }
fence.OnCompletion(2u, ToMockFenceOnCompletionCallback, userdata2); fence.OnCompletion(2u, ToMockFenceOnCompletionCallback, this + 2);
fence.OnCompletion(0u, ToMockFenceOnCompletionCallback, userdata0); fence.OnCompletion(0u, ToMockFenceOnCompletionCallback, this + 0);
fence.OnCompletion(3u, ToMockFenceOnCompletionCallback, userdata3); fence.OnCompletion(3u, ToMockFenceOnCompletionCallback, this + 3);
fence.OnCompletion(1u, ToMockFenceOnCompletionCallback, userdata1); fence.OnCompletion(1u, ToMockFenceOnCompletionCallback, this + 1);
WaitForCompletedValue(fence, 4); WaitForCompletedValue(fence, 4);
} }
@ -131,11 +125,9 @@ TEST_P(FenceTests, MultipleSignalOnCompletion) {
queue.Signal(fence, 2); queue.Signal(fence, 2);
queue.Signal(fence, 4); queue.Signal(fence, 4);
DawnCallbackUserdata userdata = 1234; EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, nullptr))
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata))
.Times(1); .Times(1);
fence.OnCompletion(3u, ToMockFenceOnCompletionCallback, userdata); fence.OnCompletion(3u, ToMockFenceOnCompletionCallback, nullptr);
WaitForCompletedValue(fence, 4); WaitForCompletedValue(fence, 4);
} }
@ -148,31 +140,26 @@ TEST_P(FenceTests, OnCompletionMultipleCallbacks) {
queue.Signal(fence, 4); queue.Signal(fence, 4);
DawnCallbackUserdata userdata0 = 2341;
DawnCallbackUserdata userdata1 = 4598;
DawnCallbackUserdata userdata2 = 5690;
DawnCallbackUserdata userdata3 = 2783;
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata0)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 0))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata1)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 1))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata2)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 2))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata3)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 3))
.Times(1); .Times(1);
fence.OnCompletion(4u, ToMockFenceOnCompletionCallback, userdata0); fence.OnCompletion(4u, ToMockFenceOnCompletionCallback, this + 0);
fence.OnCompletion(4u, ToMockFenceOnCompletionCallback, userdata1); fence.OnCompletion(4u, ToMockFenceOnCompletionCallback, this + 1);
fence.OnCompletion(4u, ToMockFenceOnCompletionCallback, userdata2); fence.OnCompletion(4u, ToMockFenceOnCompletionCallback, this + 2);
fence.OnCompletion(4u, ToMockFenceOnCompletionCallback, userdata3); fence.OnCompletion(4u, ToMockFenceOnCompletionCallback, this + 3);
WaitForCompletedValue(fence, 4u); WaitForCompletedValue(fence, 4u);
} }
@ -192,31 +179,26 @@ TEST_P(FenceTests, DISABLED_DestroyBeforeOnCompletionEnd) {
queue.Signal(testFence, 4); queue.Signal(testFence, 4);
DawnCallbackUserdata userdata0 = 1341;
DawnCallbackUserdata userdata1 = 1598;
DawnCallbackUserdata userdata2 = 1690;
DawnCallbackUserdata userdata3 = 1783;
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, userdata0)) Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, this + 0))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, userdata1)) Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, this + 1))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, userdata2)) Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, this + 2))
.Times(1); .Times(1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, userdata3)) Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, this + 3))
.Times(1); .Times(1);
testFence.OnCompletion(1u, ToMockFenceOnCompletionCallback, userdata0); testFence.OnCompletion(1u, ToMockFenceOnCompletionCallback, this + 0);
testFence.OnCompletion(2u, ToMockFenceOnCompletionCallback, userdata1); testFence.OnCompletion(2u, ToMockFenceOnCompletionCallback, this + 1);
testFence.OnCompletion(2u, ToMockFenceOnCompletionCallback, userdata2); testFence.OnCompletion(2u, ToMockFenceOnCompletionCallback, this + 2);
testFence.OnCompletion(3u, ToMockFenceOnCompletionCallback, userdata3); testFence.OnCompletion(3u, ToMockFenceOnCompletionCallback, this + 3);
} }
// Wait for another fence to be sure all callbacks have cleared // Wait for another fence to be sure all callbacks have cleared

View File

@ -26,14 +26,14 @@ class MockBufferMapReadCallback {
void(DawnBufferMapAsyncStatus status, void(DawnBufferMapAsyncStatus status,
const uint32_t* ptr, const uint32_t* ptr,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata)); void* userdata));
}; };
static std::unique_ptr<MockBufferMapReadCallback> mockBufferMapReadCallback; static std::unique_ptr<MockBufferMapReadCallback> mockBufferMapReadCallback;
static void ToMockBufferMapReadCallback(DawnBufferMapAsyncStatus status, static void ToMockBufferMapReadCallback(DawnBufferMapAsyncStatus status,
const void* ptr, const void* ptr,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata) { void* userdata) {
// Assume the data is uint32_t to make writing matchers easier // Assume the data is uint32_t to make writing matchers easier
mockBufferMapReadCallback->Call(status, reinterpret_cast<const uint32_t*>(ptr), dataLength, mockBufferMapReadCallback->Call(status, reinterpret_cast<const uint32_t*>(ptr), dataLength,
userdata); userdata);
@ -45,14 +45,14 @@ class MockBufferMapWriteCallback {
void(DawnBufferMapAsyncStatus status, void(DawnBufferMapAsyncStatus status,
uint32_t* ptr, uint32_t* ptr,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata)); void* userdata));
}; };
static std::unique_ptr<MockBufferMapWriteCallback> mockBufferMapWriteCallback; static std::unique_ptr<MockBufferMapWriteCallback> mockBufferMapWriteCallback;
static void ToMockBufferMapWriteCallback(DawnBufferMapAsyncStatus status, static void ToMockBufferMapWriteCallback(DawnBufferMapAsyncStatus status,
void* ptr, void* ptr,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata) { void* userdata) {
// Assume the data is uint32_t to make writing matchers easier // Assume the data is uint32_t to make writing matchers easier
mockBufferMapWriteCallback->Call(status, reinterpret_cast<uint32_t*>(ptr), dataLength, mockBufferMapWriteCallback->Call(status, reinterpret_cast<uint32_t*>(ptr), dataLength,
userdata); userdata);
@ -166,11 +166,10 @@ TEST_F(BufferValidationTest, CreationMapUsageRestrictions) {
TEST_F(BufferValidationTest, MapReadSuccess) { TEST_F(BufferValidationTest, MapReadSuccess) {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
dawn::CallbackUserdata userdata = 40598; buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr);
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, _))
.Times(1); .Times(1);
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
@ -181,11 +180,10 @@ TEST_F(BufferValidationTest, MapReadSuccess) {
TEST_F(BufferValidationTest, MapWriteSuccess) { TEST_F(BufferValidationTest, MapWriteSuccess) {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
dawn::CallbackUserdata userdata = 40598; buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr);
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, _))
.Times(1); .Times(1);
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
@ -208,12 +206,11 @@ TEST_F(BufferValidationTest, MapReadWrongUsage) {
dawn::Buffer buf = device.CreateBuffer(&descriptor); dawn::Buffer buf = device.CreateBuffer(&descriptor);
dawn::CallbackUserdata userdata = 40600;
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0u, _))
.Times(1); .Times(1);
ASSERT_DEVICE_ERROR(buf.MapReadAsync(ToMockBufferMapReadCallback, userdata)); ASSERT_DEVICE_ERROR(buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr));
} }
// Test map writing a buffer with wrong current usage // Test map writing a buffer with wrong current usage
@ -224,29 +221,26 @@ TEST_F(BufferValidationTest, MapWriteWrongUsage) {
dawn::Buffer buf = device.CreateBuffer(&descriptor); dawn::Buffer buf = device.CreateBuffer(&descriptor);
dawn::CallbackUserdata userdata = 40600;
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0u, _))
.Times(1); .Times(1);
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata)); ASSERT_DEVICE_ERROR(buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr));
} }
// Test map reading a buffer that is already mapped // Test map reading a buffer that is already mapped
TEST_F(BufferValidationTest, MapReadAlreadyMapped) { TEST_F(BufferValidationTest, MapReadAlreadyMapped) {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
dawn::CallbackUserdata userdata1 = 40601; buf.MapReadAsync(ToMockBufferMapReadCallback, this + 0);
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata1);
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata1)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, this + 0))
.Times(1); .Times(1);
dawn::CallbackUserdata userdata2 = 40602;
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0u, userdata2)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0u, this + 1))
.Times(1); .Times(1);
ASSERT_DEVICE_ERROR(buf.MapReadAsync(ToMockBufferMapReadCallback, userdata2)); ASSERT_DEVICE_ERROR(buf.MapReadAsync(ToMockBufferMapReadCallback, this + 1));
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
} }
@ -255,17 +249,15 @@ TEST_F(BufferValidationTest, MapReadAlreadyMapped) {
TEST_F(BufferValidationTest, MapWriteAlreadyMapped) { TEST_F(BufferValidationTest, MapWriteAlreadyMapped) {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
dawn::CallbackUserdata userdata1 = 40601; buf.MapWriteAsync(ToMockBufferMapWriteCallback, this + 0);
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata1);
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata1)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, this + 0))
.Times(1); .Times(1);
dawn::CallbackUserdata userdata2 = 40602;
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0u, userdata2)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0u, this + 1))
.Times(1); .Times(1);
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata2)); ASSERT_DEVICE_ERROR(buf.MapWriteAsync(ToMockBufferMapWriteCallback, this + 1));
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
} }
@ -275,11 +267,10 @@ TEST_F(BufferValidationTest, MapWriteAlreadyMapped) {
TEST_F(BufferValidationTest, MapReadUnmapBeforeResult) { TEST_F(BufferValidationTest, MapReadUnmapBeforeResult) {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
dawn::CallbackUserdata userdata = 40603; buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr);
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, _))
.Times(1); .Times(1);
buf.Unmap(); buf.Unmap();
@ -292,11 +283,10 @@ TEST_F(BufferValidationTest, MapReadUnmapBeforeResult) {
TEST_F(BufferValidationTest, MapWriteUnmapBeforeResult) { TEST_F(BufferValidationTest, MapWriteUnmapBeforeResult) {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
dawn::CallbackUserdata userdata = 40603; buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr);
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, _))
.Times(1); .Times(1);
buf.Unmap(); buf.Unmap();
@ -312,11 +302,10 @@ TEST_F(BufferValidationTest, DISABLED_MapReadDestroyBeforeResult) {
{ {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
dawn::CallbackUserdata userdata = 40604; buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr);
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, _))
.Times(1); .Times(1);
} }
@ -332,11 +321,10 @@ TEST_F(BufferValidationTest, DISABLED_MapWriteDestroyBeforeResult) {
{ {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
dawn::CallbackUserdata userdata = 40604; buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr);
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, _))
.Times(1); .Times(1);
} }
@ -350,20 +338,17 @@ TEST_F(BufferValidationTest, DISABLED_MapWriteDestroyBeforeResult) {
TEST_F(BufferValidationTest, MapReadUnmapBeforeResultThenMapAgain) { TEST_F(BufferValidationTest, MapReadUnmapBeforeResultThenMapAgain) {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
dawn::CallbackUserdata userdata = 40605; buf.MapReadAsync(ToMockBufferMapReadCallback, this + 0);
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, this + 0))
.Times(1); .Times(1);
buf.Unmap(); buf.Unmap();
userdata ++; buf.MapReadAsync(ToMockBufferMapReadCallback, this + 1);
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, this + 1))
.Times(1); .Times(1);
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
} }
@ -374,20 +359,17 @@ TEST_F(BufferValidationTest, MapReadUnmapBeforeResultThenMapAgain) {
TEST_F(BufferValidationTest, MapWriteUnmapBeforeResultThenMapAgain) { TEST_F(BufferValidationTest, MapWriteUnmapBeforeResultThenMapAgain) {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
dawn::CallbackUserdata userdata = 40605; buf.MapWriteAsync(ToMockBufferMapWriteCallback, this + 0);
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, this + 0))
.Times(1); .Times(1);
buf.Unmap(); buf.Unmap();
userdata ++; buf.MapWriteAsync(ToMockBufferMapWriteCallback, this + 1);
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, this + 1))
.Times(1); .Times(1);
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
} }
@ -396,11 +378,10 @@ TEST_F(BufferValidationTest, MapWriteUnmapBeforeResultThenMapAgain) {
TEST_F(BufferValidationTest, UnmapInsideMapReadCallback) { TEST_F(BufferValidationTest, UnmapInsideMapReadCallback) {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
dawn::CallbackUserdata userdata = 40678; buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr);
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, _))
.WillOnce(InvokeWithoutArgs([&]() { buf.Unmap(); })); .WillOnce(InvokeWithoutArgs([&]() { buf.Unmap(); }));
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
@ -410,11 +391,10 @@ TEST_F(BufferValidationTest, UnmapInsideMapReadCallback) {
TEST_F(BufferValidationTest, UnmapInsideMapWriteCallback) { TEST_F(BufferValidationTest, UnmapInsideMapWriteCallback) {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
dawn::CallbackUserdata userdata = 40678; buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr);
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, _))
.WillOnce(InvokeWithoutArgs([&]() { buf.Unmap(); })); .WillOnce(InvokeWithoutArgs([&]() { buf.Unmap(); }));
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
@ -424,11 +404,10 @@ TEST_F(BufferValidationTest, UnmapInsideMapWriteCallback) {
TEST_F(BufferValidationTest, DestroyInsideMapReadCallback) { TEST_F(BufferValidationTest, DestroyInsideMapReadCallback) {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
dawn::CallbackUserdata userdata = 40679; buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr);
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, _))
.WillOnce(InvokeWithoutArgs([&]() { buf = dawn::Buffer(); })); .WillOnce(InvokeWithoutArgs([&]() { buf = dawn::Buffer(); }));
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
@ -438,11 +417,10 @@ TEST_F(BufferValidationTest, DestroyInsideMapReadCallback) {
TEST_F(BufferValidationTest, DestroyInsideMapWriteCallback) { TEST_F(BufferValidationTest, DestroyInsideMapWriteCallback) {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
dawn::CallbackUserdata userdata = 40679; buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr);
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, _))
.WillOnce(InvokeWithoutArgs([&]() { buf = dawn::Buffer(); })); .WillOnce(InvokeWithoutArgs([&]() { buf = dawn::Buffer(); }));
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
@ -530,12 +508,12 @@ TEST_F(BufferValidationTest, DestroyUnmappedBuffer) {
TEST_F(BufferValidationTest, DestroyMappedBuffer) { TEST_F(BufferValidationTest, DestroyMappedBuffer) {
{ {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
buf.MapReadAsync(ToMockBufferMapReadCallback, 30303); buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr);
buf.Destroy(); buf.Destroy();
} }
{ {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
buf.MapWriteAsync(ToMockBufferMapWriteCallback, 30233); buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr);
buf.Destroy(); buf.Destroy();
} }
} }
@ -544,22 +522,20 @@ TEST_F(BufferValidationTest, DestroyMappedBuffer) {
TEST_F(BufferValidationTest, DestroyMappedBufferCausesImplicitUnmap) { TEST_F(BufferValidationTest, DestroyMappedBufferCausesImplicitUnmap) {
{ {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
dawn::CallbackUserdata userdata = 40598; buf.MapReadAsync(ToMockBufferMapReadCallback, this + 0);
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
// Buffer is destroyed. Callback should be called with UNKNOWN status // Buffer is destroyed. Callback should be called with UNKNOWN status
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, this + 0))
.Times(1); .Times(1);
buf.Destroy(); buf.Destroy();
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
} }
{ {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
dawn::CallbackUserdata userdata = 23980; buf.MapWriteAsync(ToMockBufferMapWriteCallback, this + 1);
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
// Buffer is destroyed. Callback should be called with UNKNOWN status // Buffer is destroyed. Callback should be called with UNKNOWN status
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, this + 1))
.Times(1); .Times(1);
buf.Destroy(); buf.Destroy();
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
@ -592,12 +568,12 @@ TEST_F(BufferValidationTest, MapDestroyedBuffer) {
{ {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
buf.Destroy(); buf.Destroy();
ASSERT_DEVICE_ERROR(buf.MapReadAsync(ToMockBufferMapReadCallback, 11303)); ASSERT_DEVICE_ERROR(buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr));
} }
{ {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
buf.Destroy(); buf.Destroy();
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(ToMockBufferMapWriteCallback, 56303)); ASSERT_DEVICE_ERROR(buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr));
} }
} }
@ -613,14 +589,14 @@ TEST_F(BufferValidationTest, SetSubDataDestroyedBuffer) {
TEST_F(BufferValidationTest, MapMappedbuffer) { TEST_F(BufferValidationTest, MapMappedbuffer) {
{ {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
buf.MapReadAsync(ToMockBufferMapReadCallback, 43309); buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr);
ASSERT_DEVICE_ERROR(buf.MapReadAsync(ToMockBufferMapReadCallback, 34309)); ASSERT_DEVICE_ERROR(buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr));
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
} }
{ {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
buf.MapWriteAsync(ToMockBufferMapWriteCallback, 20301); buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr);
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(ToMockBufferMapWriteCallback, 40303)); ASSERT_DEVICE_ERROR(buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr));
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
} }
} }
@ -629,14 +605,14 @@ TEST_F(BufferValidationTest, MapMappedbuffer) {
TEST_F(BufferValidationTest, SetSubDataMappedBuffer) { TEST_F(BufferValidationTest, SetSubDataMappedBuffer) {
{ {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
buf.MapReadAsync(ToMockBufferMapReadCallback, 42899); buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr);
uint8_t foo = 0; uint8_t foo = 0;
ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(foo), &foo)); ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(foo), &foo));
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
} }
{ {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
buf.MapWriteAsync(ToMockBufferMapWriteCallback, 40329); buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr);
uint8_t foo = 0; uint8_t foo = 0;
ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(foo), &foo)); ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(foo), &foo));
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
@ -675,7 +651,7 @@ TEST_F(BufferValidationTest, SubmitMappedBuffer) {
dawn::Buffer bufA = device.CreateBuffer(&descriptorA); dawn::Buffer bufA = device.CreateBuffer(&descriptorA);
dawn::Buffer bufB = device.CreateBuffer(&descriptorB); dawn::Buffer bufB = device.CreateBuffer(&descriptorB);
bufA.MapWriteAsync(ToMockBufferMapWriteCallback, 40329); bufA.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); dawn::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToBuffer(bufA, 0, bufB, 0, 4); encoder.CopyBufferToBuffer(bufA, 0, bufB, 0, 4);
@ -687,7 +663,7 @@ TEST_F(BufferValidationTest, SubmitMappedBuffer) {
dawn::Buffer bufA = device.CreateBuffer(&descriptorA); dawn::Buffer bufA = device.CreateBuffer(&descriptorA);
dawn::Buffer bufB = device.CreateBuffer(&descriptorB); dawn::Buffer bufB = device.CreateBuffer(&descriptorB);
bufB.MapReadAsync(ToMockBufferMapReadCallback, 11329); bufB.MapReadAsync(ToMockBufferMapReadCallback, nullptr);
dawn::CommandEncoder encoder = device.CreateCommandEncoder(); dawn::CommandEncoder encoder = device.CreateCommandEncoder();
encoder.CopyBufferToBuffer(bufA, 0, bufB, 0, 4); encoder.CopyBufferToBuffer(bufA, 0, bufB, 0, 4);
@ -729,7 +705,7 @@ TEST_F(BufferValidationTest, UnmapUnmappedBuffer) {
dawn::Buffer buf = CreateMapReadBuffer(4); dawn::Buffer buf = CreateMapReadBuffer(4);
// Buffer starts unmapped. Unmap should succeed. // Buffer starts unmapped. Unmap should succeed.
buf.Unmap(); buf.Unmap();
buf.MapReadAsync(ToMockBufferMapReadCallback, 30603); buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr);
buf.Unmap(); buf.Unmap();
// Unmapping twice should succeed // Unmapping twice should succeed
buf.Unmap(); buf.Unmap();
@ -738,7 +714,7 @@ TEST_F(BufferValidationTest, UnmapUnmappedBuffer) {
dawn::Buffer buf = CreateMapWriteBuffer(4); dawn::Buffer buf = CreateMapWriteBuffer(4);
// Buffer starts unmapped. Unmap should succeed. // Buffer starts unmapped. Unmap should succeed.
buf.Unmap(); buf.Unmap();
buf.MapWriteAsync(ToMockBufferMapWriteCallback, 23890); buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr);
// Unmapping twice should succeed // Unmapping twice should succeed
buf.Unmap(); buf.Unmap();
buf.Unmap(); buf.Unmap();

View File

@ -20,7 +20,7 @@ using namespace testing;
class MockFenceOnCompletionCallback { class MockFenceOnCompletionCallback {
public: public:
MOCK_METHOD2(Call, void(DawnFenceCompletionStatus status, DawnCallbackUserdata userdata)); MOCK_METHOD2(Call, void(DawnFenceCompletionStatus status, void* userdata));
}; };
struct FenceOnCompletionExpectation { struct FenceOnCompletionExpectation {
@ -30,8 +30,7 @@ struct FenceOnCompletionExpectation {
}; };
static std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback; static std::unique_ptr<MockFenceOnCompletionCallback> mockFenceOnCompletionCallback;
static void ToMockFenceOnCompletionCallback(DawnFenceCompletionStatus status, static void ToMockFenceOnCompletionCallback(DawnFenceCompletionStatus status, void* userdata) {
DawnCallbackUserdata userdata) {
mockFenceOnCompletionCallback->Call(status, userdata); mockFenceOnCompletionCallback->Call(status, userdata);
} }
@ -42,11 +41,9 @@ class FenceValidationTest : public ValidationTest {
expectation->fence = fence; expectation->fence = fence;
expectation->value = value; expectation->value = value;
expectation->status = status; expectation->status = status;
DawnCallbackUserdata userdata =
static_cast<DawnCallbackUserdata>(reinterpret_cast<uintptr_t>(expectation));
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(status, userdata)).Times(1); EXPECT_CALL(*mockFenceOnCompletionCallback, Call(status, expectation)).Times(1);
fence.OnCompletion(value, ToMockFenceOnCompletionCallback, userdata); fence.OnCompletion(value, ToMockFenceOnCompletionCallback, expectation);
} }
void Flush() { void Flush() {
@ -98,13 +95,15 @@ TEST_F(FenceValidationTest, OnCompletionImmediate) {
descriptor.initialValue = 1; descriptor.initialValue = 1;
dawn::Fence fence = queue.CreateFence(&descriptor); dawn::Fence fence = queue.CreateFence(&descriptor);
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, 0)) EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 0))
.Times(1); .Times(1);
fence.OnCompletion(0u, ToMockFenceOnCompletionCallback, 0); fence.OnCompletion(0u, ToMockFenceOnCompletionCallback, this + 0);
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, 1)) EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 1))
.Times(1); .Times(1);
fence.OnCompletion(1u, ToMockFenceOnCompletionCallback, 1); fence.OnCompletion(1u, ToMockFenceOnCompletionCallback, this + 1);
} }
// Test setting OnCompletion handlers for values > signaled value // Test setting OnCompletion handlers for values > signaled value
@ -114,15 +113,15 @@ TEST_F(FenceValidationTest, OnCompletionLargerThanSignaled) {
dawn::Fence fence = queue.CreateFence(&descriptor); dawn::Fence fence = queue.CreateFence(&descriptor);
// Cannot signal for values > signaled value // Cannot signal for values > signaled value
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_ERROR, 0)) EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_ERROR, nullptr))
.Times(1); .Times(1);
ASSERT_DEVICE_ERROR(fence.OnCompletion(2u, ToMockFenceOnCompletionCallback, 0)); ASSERT_DEVICE_ERROR(fence.OnCompletion(2u, ToMockFenceOnCompletionCallback, nullptr));
// Can set handler after signaling // Can set handler after signaling
queue.Signal(fence, 2); queue.Signal(fence, 2);
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, 0)) EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, nullptr))
.Times(1); .Times(1);
fence.OnCompletion(2u, ToMockFenceOnCompletionCallback, 0); fence.OnCompletion(2u, ToMockFenceOnCompletionCallback, nullptr);
Flush(); Flush();
} }
@ -133,9 +132,9 @@ TEST_F(FenceValidationTest, GetCompletedValueInsideCallback) {
dawn::Fence fence = queue.CreateFence(&descriptor); dawn::Fence fence = queue.CreateFence(&descriptor);
queue.Signal(fence, 3); queue.Signal(fence, 3);
fence.OnCompletion(2u, ToMockFenceOnCompletionCallback, 0); fence.OnCompletion(2u, ToMockFenceOnCompletionCallback, nullptr);
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, 0)) EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, nullptr))
.WillOnce(Invoke([&](DawnFenceCompletionStatus status, DawnCallbackUserdata userdata) { .WillOnce(Invoke([&](DawnFenceCompletionStatus status, void* userdata) {
EXPECT_EQ(fence.GetCompletedValue(), 3u); EXPECT_EQ(fence.GetCompletedValue(), 3u);
})); }));
@ -148,8 +147,8 @@ TEST_F(FenceValidationTest, GetCompletedValueAfterCallback) {
dawn::Fence fence = queue.CreateFence(&descriptor); dawn::Fence fence = queue.CreateFence(&descriptor);
queue.Signal(fence, 2); queue.Signal(fence, 2);
fence.OnCompletion(2u, ToMockFenceOnCompletionCallback, 0); fence.OnCompletion(2u, ToMockFenceOnCompletionCallback, nullptr);
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, 0)) EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, nullptr))
.Times(1); .Times(1);
Flush(); Flush();

View File

@ -24,9 +24,8 @@ class QueueSubmitValidationTest : public ValidationTest {
static void StoreTrueMapWriteCallback(DawnBufferMapAsyncStatus status, static void StoreTrueMapWriteCallback(DawnBufferMapAsyncStatus status,
void*, void*,
uint64_t, uint64_t,
DawnCallbackUserdata userdata) { void* userdata) {
bool* userdataPtr = reinterpret_cast<bool*>(static_cast<intptr_t>(userdata)); *static_cast<bool*>(userdata) = true;
*userdataPtr = true;
} }
// Test submitting with a mapped buffer is disallowed // Test submitting with a mapped buffer is disallowed
@ -56,8 +55,7 @@ TEST_F(QueueSubmitValidationTest, SubmitWithMappedBuffer) {
// Map the buffer, submitting when the buffer is mapped should fail // Map the buffer, submitting when the buffer is mapped should fail
bool mapWriteFinished = false; bool mapWriteFinished = false;
DawnCallbackUserdata userdata = static_cast<DawnCallbackUserdata>(reinterpret_cast<intptr_t>(&mapWriteFinished)); buffer.MapWriteAsync(StoreTrueMapWriteCallback, &mapWriteFinished);
buffer.MapWriteAsync(StoreTrueMapWriteCallback, userdata);
queue.Submit(0, nullptr); queue.Submit(0, nullptr);
ASSERT_TRUE(mapWriteFinished); ASSERT_TRUE(mapWriteFinished);

View File

@ -40,7 +40,7 @@ ValidationTest::ValidationTest() {
DawnProcTable procs = dawn_native::GetProcs(); DawnProcTable procs = dawn_native::GetProcs();
dawnSetProcs(&procs); dawnSetProcs(&procs);
device.SetErrorCallback(ValidationTest::OnDeviceError, static_cast<DawnCallbackUserdata>(reinterpret_cast<uintptr_t>(this))); device.SetErrorCallback(ValidationTest::OnDeviceError, this);
} }
ValidationTest::~ValidationTest() { ValidationTest::~ValidationTest() {
@ -67,8 +67,8 @@ std::string ValidationTest::GetLastDeviceErrorMessage() const {
} }
// static // static
void ValidationTest::OnDeviceError(const char* message, DawnCallbackUserdata userdata) { void ValidationTest::OnDeviceError(const char* message, void* userdata) {
auto self = reinterpret_cast<ValidationTest*>(static_cast<uintptr_t>(userdata)); auto self = static_cast<ValidationTest*>(userdata);
self->mDeviceErrorMessage = message; self->mDeviceErrorMessage = message;
ASSERT_TRUE(self->mExpectError) << "Got unexpected device error: " << message; ASSERT_TRUE(self->mExpectError) << "Got unexpected device error: " << message;

View File

@ -37,7 +37,7 @@ class ValidationTest : public testing::Test {
// Helper functions to create objects to test validation. // Helper functions to create objects to test validation.
struct DummyRenderPass : public dawn::RenderPassDescriptor{ struct DummyRenderPass : public dawn::RenderPassDescriptor {
public: public:
DummyRenderPass(const dawn::Device& device); DummyRenderPass(const dawn::Device& device);
dawn::Texture attachment; dawn::Texture attachment;
@ -56,7 +56,7 @@ class ValidationTest : public testing::Test {
std::unique_ptr<dawn_native::Instance> instance; std::unique_ptr<dawn_native::Instance> instance;
private: private:
static void OnDeviceError(const char* message, DawnCallbackUserdata userdata); static void OnDeviceError(const char* message, void* userdata);
std::string mDeviceErrorMessage; std::string mDeviceErrorMessage;
bool mExpectError = false; bool mExpectError = false;
bool mError = false; bool mError = false;

View File

@ -26,14 +26,14 @@ namespace {
void(DawnBufferMapAsyncStatus status, void(DawnBufferMapAsyncStatus status,
const uint32_t* ptr, const uint32_t* ptr,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata)); void* userdata));
}; };
std::unique_ptr<StrictMock<MockBufferMapReadCallback>> mockBufferMapReadCallback; std::unique_ptr<StrictMock<MockBufferMapReadCallback>> mockBufferMapReadCallback;
void ToMockBufferMapReadCallback(DawnBufferMapAsyncStatus status, void ToMockBufferMapReadCallback(DawnBufferMapAsyncStatus status,
const void* ptr, const void* ptr,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata) { void* userdata) {
// Assume the data is uint32_t to make writing matchers easier // Assume the data is uint32_t to make writing matchers easier
mockBufferMapReadCallback->Call(status, static_cast<const uint32_t*>(ptr), dataLength, mockBufferMapReadCallback->Call(status, static_cast<const uint32_t*>(ptr), dataLength,
userdata); userdata);
@ -45,7 +45,7 @@ namespace {
void(DawnBufferMapAsyncStatus status, void(DawnBufferMapAsyncStatus status,
uint32_t* ptr, uint32_t* ptr,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata)); void* userdata));
}; };
std::unique_ptr<StrictMock<MockBufferMapWriteCallback>> mockBufferMapWriteCallback; std::unique_ptr<StrictMock<MockBufferMapWriteCallback>> mockBufferMapWriteCallback;
@ -53,7 +53,7 @@ namespace {
void ToMockBufferMapWriteCallback(DawnBufferMapAsyncStatus status, void ToMockBufferMapWriteCallback(DawnBufferMapAsyncStatus status,
void* ptr, void* ptr,
uint64_t dataLength, uint64_t dataLength,
DawnCallbackUserdata userdata) { void* userdata) {
// Assume the data is uint32_t to make writing matchers easier // Assume the data is uint32_t to make writing matchers easier
lastMapWritePointer = static_cast<uint32_t*>(ptr); lastMapWritePointer = static_cast<uint32_t*>(ptr);
mockBufferMapWriteCallback->Call(status, lastMapWritePointer, dataLength, userdata); mockBufferMapWriteCallback->Call(status, lastMapWritePointer, dataLength, userdata);
@ -110,8 +110,7 @@ class WireBufferMappingTests : public WireTest {
// Check mapping for reading a succesfully created buffer // Check mapping for reading a succesfully created buffer
TEST_F(WireBufferMappingTests, MappingForReadSuccessBuffer) { TEST_F(WireBufferMappingTests, MappingForReadSuccessBuffer) {
DawnCallbackUserdata userdata = 8653; dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
@ -122,9 +121,8 @@ TEST_F(WireBufferMappingTests, MappingForReadSuccessBuffer) {
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)), Pointee(Eq(bufferContent)), sizeof(uint32_t), _))
sizeof(uint32_t), userdata))
.Times(1); .Times(1);
FlushServer(); FlushServer();
@ -138,8 +136,7 @@ TEST_F(WireBufferMappingTests, MappingForReadSuccessBuffer) {
// Check that things work correctly when a validation error happens when mapping the buffer for // Check that things work correctly when a validation error happens when mapping the buffer for
// reading // reading
TEST_F(WireBufferMappingTests, ErrorWhileMappingForRead) { TEST_F(WireBufferMappingTests, ErrorWhileMappingForRead) {
DawnCallbackUserdata userdata = 8654; dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() { .WillOnce(InvokeWithoutArgs([&]() {
@ -148,8 +145,7 @@ TEST_F(WireBufferMappingTests, ErrorWhileMappingForRead) {
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, _))
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata))
.Times(1); .Times(1);
FlushServer(); FlushServer();
@ -158,8 +154,7 @@ TEST_F(WireBufferMappingTests, ErrorWhileMappingForRead) {
// Check that the map read callback is called with UNKNOWN when the buffer is destroyed before the // Check that the map read callback is called with UNKNOWN when the buffer is destroyed before the
// request is finished // request is finished
TEST_F(WireBufferMappingTests, DestroyBeforeReadRequestEnd) { TEST_F(WireBufferMappingTests, DestroyBeforeReadRequestEnd) {
DawnCallbackUserdata userdata = 8656; dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
// Return success // Return success
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
@ -169,7 +164,7 @@ TEST_F(WireBufferMappingTests, DestroyBeforeReadRequestEnd) {
// Destroy before the client gets the success, so the callback is called with unknown. // Destroy before the client gets the success, so the callback is called with unknown.
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, _))
.Times(1); .Times(1);
dawnBufferRelease(buffer); dawnBufferRelease(buffer);
EXPECT_CALL(api, BufferRelease(apiBuffer)); EXPECT_CALL(api, BufferRelease(apiBuffer));
@ -181,8 +176,7 @@ TEST_F(WireBufferMappingTests, DestroyBeforeReadRequestEnd) {
// Check the map read callback is called with UNKNOWN when the map request would have worked, but // Check the map read callback is called with UNKNOWN when the map request would have worked, but
// Unmap was called // Unmap was called
TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForRead) { TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForRead) {
DawnCallbackUserdata userdata = 8657; dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
@ -195,7 +189,7 @@ TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForRead) {
// Oh no! We are calling Unmap too early! // Oh no! We are calling Unmap too early!
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, _))
.Times(1); .Times(1);
dawnBufferUnmap(buffer); dawnBufferUnmap(buffer);
@ -206,8 +200,7 @@ TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForRead) {
// Check that an error map read callback gets nullptr while a buffer is already mapped // Check that an error map read callback gets nullptr while a buffer is already mapped
TEST_F(WireBufferMappingTests, MappingForReadingErrorWhileAlreadyMappedGetsNullptr) { TEST_F(WireBufferMappingTests, MappingForReadingErrorWhileAlreadyMappedGetsNullptr) {
// Successful map // Successful map
DawnCallbackUserdata userdata = 34098; dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
@ -219,16 +212,14 @@ TEST_F(WireBufferMappingTests, MappingForReadingErrorWhileAlreadyMappedGetsNullp
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)), Pointee(Eq(bufferContent)), sizeof(uint32_t), _))
sizeof(uint32_t), userdata))
.Times(1); .Times(1);
FlushServer(); FlushServer();
// Map failure while the buffer is already mapped // Map failure while the buffer is already mapped
userdata++; dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() { .WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0); api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0);
@ -236,8 +227,7 @@ TEST_F(WireBufferMappingTests, MappingForReadingErrorWhileAlreadyMappedGetsNullp
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, _))
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata))
.Times(1); .Times(1);
FlushServer(); FlushServer();
@ -245,8 +235,7 @@ TEST_F(WireBufferMappingTests, MappingForReadingErrorWhileAlreadyMappedGetsNullp
// Test that the MapReadCallback isn't fired twice when unmap() is called inside the callback // Test that the MapReadCallback isn't fired twice when unmap() is called inside the callback
TEST_F(WireBufferMappingTests, UnmapInsideMapReadCallback) { TEST_F(WireBufferMappingTests, UnmapInsideMapReadCallback) {
DawnCallbackUserdata userdata = 2039; dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
@ -257,9 +246,8 @@ TEST_F(WireBufferMappingTests, UnmapInsideMapReadCallback) {
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)), Pointee(Eq(bufferContent)), sizeof(uint32_t), _))
sizeof(uint32_t), userdata))
.WillOnce(InvokeWithoutArgs([&]() { dawnBufferUnmap(buffer); })); .WillOnce(InvokeWithoutArgs([&]() { dawnBufferUnmap(buffer); }));
FlushServer(); FlushServer();
@ -272,8 +260,7 @@ TEST_F(WireBufferMappingTests, UnmapInsideMapReadCallback) {
// Test that the MapReadCallback isn't fired twice the buffer external refcount reaches 0 in the // Test that the MapReadCallback isn't fired twice the buffer external refcount reaches 0 in the
// callback // callback
TEST_F(WireBufferMappingTests, DestroyInsideMapReadCallback) { TEST_F(WireBufferMappingTests, DestroyInsideMapReadCallback) {
DawnCallbackUserdata userdata = 2039; dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, nullptr);
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
@ -284,9 +271,8 @@ TEST_F(WireBufferMappingTests, DestroyInsideMapReadCallback) {
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)), Pointee(Eq(bufferContent)), sizeof(uint32_t), _))
sizeof(uint32_t), userdata))
.WillOnce(InvokeWithoutArgs([&]() { dawnBufferRelease(buffer); })); .WillOnce(InvokeWithoutArgs([&]() { dawnBufferRelease(buffer); }));
FlushServer(); FlushServer();
@ -300,8 +286,7 @@ TEST_F(WireBufferMappingTests, DestroyInsideMapReadCallback) {
// Check mapping for writing a succesfully created buffer // Check mapping for writing a succesfully created buffer
TEST_F(WireBufferMappingTests, MappingForWriteSuccessBuffer) { TEST_F(WireBufferMappingTests, MappingForWriteSuccessBuffer) {
DawnCallbackUserdata userdata = 8653; dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, nullptr);
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
uint32_t serverBufferContent = 31337; uint32_t serverBufferContent = 31337;
uint32_t updatedContent = 4242; uint32_t updatedContent = 4242;
@ -316,8 +301,8 @@ TEST_F(WireBufferMappingTests, MappingForWriteSuccessBuffer) {
FlushClient(); FlushClient();
// The map write callback always gets a buffer full of zeroes. // The map write callback always gets a buffer full of zeroes.
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, EXPECT_CALL(*mockBufferMapWriteCallback,
Pointee(Eq(zero)), sizeof(uint32_t), userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(zero)), sizeof(uint32_t), _))
.Times(1); .Times(1);
FlushServer(); FlushServer();
@ -337,8 +322,7 @@ TEST_F(WireBufferMappingTests, MappingForWriteSuccessBuffer) {
// Check that things work correctly when a validation error happens when mapping the buffer for // Check that things work correctly when a validation error happens when mapping the buffer for
// writing // writing
TEST_F(WireBufferMappingTests, ErrorWhileMappingForWrite) { TEST_F(WireBufferMappingTests, ErrorWhileMappingForWrite) {
DawnCallbackUserdata userdata = 8654; dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, nullptr);
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() { .WillOnce(InvokeWithoutArgs([&]() {
@ -348,7 +332,7 @@ TEST_F(WireBufferMappingTests, ErrorWhileMappingForWrite) {
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, _))
.Times(1); .Times(1);
FlushServer(); FlushServer();
@ -357,8 +341,7 @@ TEST_F(WireBufferMappingTests, ErrorWhileMappingForWrite) {
// Check that the map write callback is called with UNKNOWN when the buffer is destroyed before the // Check that the map write callback is called with UNKNOWN when the buffer is destroyed before the
// request is finished // request is finished
TEST_F(WireBufferMappingTests, DestroyBeforeWriteRequestEnd) { TEST_F(WireBufferMappingTests, DestroyBeforeWriteRequestEnd) {
DawnCallbackUserdata userdata = 8656; dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, nullptr);
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
// Return success // Return success
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
@ -368,7 +351,7 @@ TEST_F(WireBufferMappingTests, DestroyBeforeWriteRequestEnd) {
// Destroy before the client gets the success, so the callback is called with unknown. // Destroy before the client gets the success, so the callback is called with unknown.
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, _))
.Times(1); .Times(1);
dawnBufferRelease(buffer); dawnBufferRelease(buffer);
EXPECT_CALL(api, BufferRelease(apiBuffer)); EXPECT_CALL(api, BufferRelease(apiBuffer));
@ -380,8 +363,7 @@ TEST_F(WireBufferMappingTests, DestroyBeforeWriteRequestEnd) {
// Check the map read callback is called with UNKNOWN when the map request would have worked, but // Check the map read callback is called with UNKNOWN when the map request would have worked, but
// Unmap was called // Unmap was called
TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForWrite) { TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForWrite) {
DawnCallbackUserdata userdata = 8657; dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, nullptr);
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
@ -394,7 +376,7 @@ TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForWrite) {
// Oh no! We are calling Unmap too early! // Oh no! We are calling Unmap too early!
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, _))
.Times(1); .Times(1);
dawnBufferUnmap(buffer); dawnBufferUnmap(buffer);
@ -405,8 +387,7 @@ TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForWrite) {
// Check that an error map read callback gets nullptr while a buffer is already mapped // Check that an error map read callback gets nullptr while a buffer is already mapped
TEST_F(WireBufferMappingTests, MappingForWritingErrorWhileAlreadyMappedGetsNullptr) { TEST_F(WireBufferMappingTests, MappingForWritingErrorWhileAlreadyMappedGetsNullptr) {
// Successful map // Successful map
DawnCallbackUserdata userdata = 34098; dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, nullptr);
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
uint32_t zero = 0; uint32_t zero = 0;
@ -419,15 +400,14 @@ TEST_F(WireBufferMappingTests, MappingForWritingErrorWhileAlreadyMappedGetsNullp
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, EXPECT_CALL(*mockBufferMapWriteCallback,
Pointee(Eq(zero)), sizeof(uint32_t), userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(zero)), sizeof(uint32_t), _))
.Times(1); .Times(1);
FlushServer(); FlushServer();
// Map failure while the buffer is already mapped // Map failure while the buffer is already mapped
userdata++; dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, nullptr);
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() { .WillOnce(InvokeWithoutArgs([&]() {
api.CallMapWriteCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0); api.CallMapWriteCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0);
@ -436,7 +416,7 @@ TEST_F(WireBufferMappingTests, MappingForWritingErrorWhileAlreadyMappedGetsNullp
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, _))
.Times(1); .Times(1);
FlushServer(); FlushServer();
@ -444,8 +424,7 @@ TEST_F(WireBufferMappingTests, MappingForWritingErrorWhileAlreadyMappedGetsNullp
// Test that the MapWriteCallback isn't fired twice when unmap() is called inside the callback // Test that the MapWriteCallback isn't fired twice when unmap() is called inside the callback
TEST_F(WireBufferMappingTests, UnmapInsideMapWriteCallback) { TEST_F(WireBufferMappingTests, UnmapInsideMapWriteCallback) {
DawnCallbackUserdata userdata = 2039; dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, nullptr);
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
uint32_t zero = 0; uint32_t zero = 0;
@ -457,8 +436,8 @@ TEST_F(WireBufferMappingTests, UnmapInsideMapWriteCallback) {
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, EXPECT_CALL(*mockBufferMapWriteCallback,
Pointee(Eq(zero)), sizeof(uint32_t), userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(zero)), sizeof(uint32_t), _))
.WillOnce(InvokeWithoutArgs([&]() { dawnBufferUnmap(buffer); })); .WillOnce(InvokeWithoutArgs([&]() { dawnBufferUnmap(buffer); }));
FlushServer(); FlushServer();
@ -471,8 +450,7 @@ TEST_F(WireBufferMappingTests, UnmapInsideMapWriteCallback) {
// Test that the MapWriteCallback isn't fired twice the buffer external refcount reaches 0 in the // Test that the MapWriteCallback isn't fired twice the buffer external refcount reaches 0 in the
// callback // callback
TEST_F(WireBufferMappingTests, DestroyInsideMapWriteCallback) { TEST_F(WireBufferMappingTests, DestroyInsideMapWriteCallback) {
DawnCallbackUserdata userdata = 2039; dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, nullptr);
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
uint32_t bufferContent = 31337; uint32_t bufferContent = 31337;
uint32_t zero = 0; uint32_t zero = 0;
@ -484,8 +462,8 @@ TEST_F(WireBufferMappingTests, DestroyInsideMapWriteCallback) {
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, EXPECT_CALL(*mockBufferMapWriteCallback,
Pointee(Eq(zero)), sizeof(uint32_t), userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(zero)), sizeof(uint32_t), _))
.WillOnce(InvokeWithoutArgs([&]() { dawnBufferRelease(buffer); })); .WillOnce(InvokeWithoutArgs([&]() { dawnBufferRelease(buffer); }));
FlushServer(); FlushServer();
@ -575,8 +553,7 @@ TEST_F(WireBufferMappingTests, CreateBufferMappedThenMapSuccess) {
FlushClient(); FlushClient();
DawnCallbackUserdata userdata = 2499; dawnBufferMapWriteAsync(result.buffer, ToMockBufferMapWriteCallback, nullptr);
dawnBufferMapWriteAsync(result.buffer, ToMockBufferMapWriteCallback, userdata);
uint32_t zero = 0; uint32_t zero = 0;
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
@ -588,8 +565,7 @@ TEST_F(WireBufferMappingTests, CreateBufferMappedThenMapSuccess) {
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(zero)), sizeof(uint32_t), _))
Pointee(Eq(zero)), sizeof(uint32_t), userdata))
.Times(1); .Times(1);
FlushServer(); FlushServer();
@ -616,8 +592,7 @@ TEST_F(WireBufferMappingTests, CreateBufferMappedThenMapFailure) {
FlushClient(); FlushClient();
DawnCallbackUserdata userdata = 2499; dawnBufferMapWriteAsync(result.buffer, ToMockBufferMapWriteCallback, nullptr);
dawnBufferMapWriteAsync(result.buffer, ToMockBufferMapWriteCallback, userdata);
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _)) EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
.WillOnce(InvokeWithoutArgs([&]() { .WillOnce(InvokeWithoutArgs([&]() {
@ -627,7 +602,7 @@ TEST_F(WireBufferMappingTests, CreateBufferMappedThenMapFailure) {
FlushClient(); FlushClient();
EXPECT_CALL(*mockBufferMapWriteCallback, EXPECT_CALL(*mockBufferMapWriteCallback,
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata)) Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, _))
.Times(1); .Times(1);
FlushServer(); FlushServer();

View File

@ -22,11 +22,11 @@ namespace {
// Mock classes to add expectations on the wire calling callbacks // Mock classes to add expectations on the wire calling callbacks
class MockDeviceErrorCallback { class MockDeviceErrorCallback {
public: public:
MOCK_METHOD2(Call, void(const char* message, DawnCallbackUserdata userdata)); MOCK_METHOD2(Call, void(const char* message, void* userdata));
}; };
std::unique_ptr<StrictMock<MockDeviceErrorCallback>> mockDeviceErrorCallback; std::unique_ptr<StrictMock<MockDeviceErrorCallback>> mockDeviceErrorCallback;
void ToMockDeviceErrorCallback(const char* message, DawnCallbackUserdata userdata) { void ToMockDeviceErrorCallback(const char* message, void* userdata) {
mockDeviceErrorCallback->Call(message, userdata); mockDeviceErrorCallback->Call(message, userdata);
} }
@ -59,8 +59,7 @@ class WireErrorCallbackTests : public WireTest {
// Test the return wire for device error callbacks // Test the return wire for device error callbacks
TEST_F(WireErrorCallbackTests, DeviceErrorCallback) { TEST_F(WireErrorCallbackTests, DeviceErrorCallback) {
uint64_t userdata = 3049785; dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, this);
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
// Setting the error callback should stay on the client side and do nothing // Setting the error callback should stay on the client side and do nothing
FlushClient(); FlushClient();
@ -69,7 +68,7 @@ TEST_F(WireErrorCallbackTests, DeviceErrorCallback) {
// client side // client side
api.CallDeviceErrorCallback(apiDevice, "Some error message"); api.CallDeviceErrorCallback(apiDevice, "Some error message");
EXPECT_CALL(*mockDeviceErrorCallback, Call(StrEq("Some error message"), userdata)).Times(1); EXPECT_CALL(*mockDeviceErrorCallback, Call(StrEq("Some error message"), this)).Times(1);
FlushServer(); FlushServer();
} }

View File

@ -22,22 +22,21 @@ namespace {
// Mock classes to add expectations on the wire calling callbacks // Mock classes to add expectations on the wire calling callbacks
class MockDeviceErrorCallback { class MockDeviceErrorCallback {
public: public:
MOCK_METHOD2(Call, void(const char* message, DawnCallbackUserdata userdata)); MOCK_METHOD2(Call, void(const char* message, void* userdata));
}; };
std::unique_ptr<StrictMock<MockDeviceErrorCallback>> mockDeviceErrorCallback; std::unique_ptr<StrictMock<MockDeviceErrorCallback>> mockDeviceErrorCallback;
void ToMockDeviceErrorCallback(const char* message, DawnCallbackUserdata userdata) { void ToMockDeviceErrorCallback(const char* message, void* userdata) {
mockDeviceErrorCallback->Call(message, userdata); mockDeviceErrorCallback->Call(message, userdata);
} }
class MockFenceOnCompletionCallback { class MockFenceOnCompletionCallback {
public: public:
MOCK_METHOD2(Call, void(DawnFenceCompletionStatus status, DawnCallbackUserdata userdata)); MOCK_METHOD2(Call, void(DawnFenceCompletionStatus status, void* userdata));
}; };
std::unique_ptr<StrictMock<MockFenceOnCompletionCallback>> mockFenceOnCompletionCallback; std::unique_ptr<StrictMock<MockFenceOnCompletionCallback>> mockFenceOnCompletionCallback;
void ToMockFenceOnCompletionCallback(DawnFenceCompletionStatus status, void ToMockFenceOnCompletionCallback(DawnFenceCompletionStatus status, void* userdata) {
DawnCallbackUserdata userdata) {
mockFenceOnCompletionCallback->Call(status, userdata); mockFenceOnCompletionCallback->Call(status, userdata);
} }
@ -121,9 +120,8 @@ TEST_F(WireFenceTests, QueueSignalSuccess) {
// Without any flushes, it is valid to signal a value greater than the current // Without any flushes, it is valid to signal a value greater than the current
// signaled value // signaled value
TEST_F(WireFenceTests, QueueSignalSynchronousValidationSuccess) { TEST_F(WireFenceTests, QueueSignalSynchronousValidationSuccess) {
DawnCallbackUserdata userdata = 9157; dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, nullptr);
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata); EXPECT_CALL(*mockDeviceErrorCallback, Call(_, _)).Times(0);
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(0);
dawnQueueSignal(queue, fence, 2u); dawnQueueSignal(queue, fence, 2u);
dawnQueueSignal(queue, fence, 4u); dawnQueueSignal(queue, fence, 4u);
@ -133,22 +131,21 @@ TEST_F(WireFenceTests, QueueSignalSynchronousValidationSuccess) {
// Without any flushes, errors should be generated when signaling a value less // Without any flushes, errors should be generated when signaling a value less
// than or equal to the current signaled value // than or equal to the current signaled value
TEST_F(WireFenceTests, QueueSignalSynchronousValidationError) { TEST_F(WireFenceTests, QueueSignalSynchronousValidationError) {
DawnCallbackUserdata userdata = 3157; dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, nullptr);
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata);
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1); EXPECT_CALL(*mockDeviceErrorCallback, Call(_, _)).Times(1);
dawnQueueSignal(queue, fence, 0u); // Error dawnQueueSignal(queue, fence, 0u); // Error
EXPECT_TRUE(Mock::VerifyAndClear(mockDeviceErrorCallback.get())); EXPECT_TRUE(Mock::VerifyAndClear(mockDeviceErrorCallback.get()));
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1); EXPECT_CALL(*mockDeviceErrorCallback, Call(_, _)).Times(1);
dawnQueueSignal(queue, fence, 1u); // Error dawnQueueSignal(queue, fence, 1u); // Error
EXPECT_TRUE(Mock::VerifyAndClear(mockDeviceErrorCallback.get())); EXPECT_TRUE(Mock::VerifyAndClear(mockDeviceErrorCallback.get()));
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(0); EXPECT_CALL(*mockDeviceErrorCallback, Call(_, _)).Times(0);
dawnQueueSignal(queue, fence, 4u); // Success dawnQueueSignal(queue, fence, 4u); // Success
EXPECT_TRUE(Mock::VerifyAndClear(mockDeviceErrorCallback.get())); EXPECT_TRUE(Mock::VerifyAndClear(mockDeviceErrorCallback.get()));
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1); EXPECT_CALL(*mockDeviceErrorCallback, Call(_, _)).Times(1);
dawnQueueSignal(queue, fence, 3u); // Error dawnQueueSignal(queue, fence, 3u); // Error
EXPECT_TRUE(Mock::VerifyAndClear(mockDeviceErrorCallback.get())); EXPECT_TRUE(Mock::VerifyAndClear(mockDeviceErrorCallback.get()));
} }
@ -157,20 +154,16 @@ TEST_F(WireFenceTests, QueueSignalSynchronousValidationError) {
TEST_F(WireFenceTests, OnCompletionImmediate) { TEST_F(WireFenceTests, OnCompletionImmediate) {
// Can call on value < (initial) signaled value happens immediately // Can call on value < (initial) signaled value happens immediately
{ {
DawnCallbackUserdata userdata = 9847; EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, _))
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata))
.Times(1); .Times(1);
dawnFenceOnCompletion(fence, 0, ToMockFenceOnCompletionCallback, userdata); dawnFenceOnCompletion(fence, 0, ToMockFenceOnCompletionCallback, nullptr);
} }
// Can call on value == (initial) signaled value happens immediately // Can call on value == (initial) signaled value happens immediately
{ {
DawnCallbackUserdata userdata = 4347; EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, _))
EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata))
.Times(1); .Times(1);
dawnFenceOnCompletion(fence, 1, ToMockFenceOnCompletionCallback, userdata); dawnFenceOnCompletion(fence, 1, ToMockFenceOnCompletionCallback, nullptr);
} }
} }
@ -179,34 +172,29 @@ TEST_F(WireFenceTests, OnCompletionMultiple) {
DoQueueSignal(3u); DoQueueSignal(3u);
DoQueueSignal(6u); DoQueueSignal(6u);
DawnCallbackUserdata userdata0 = 2134;
DawnCallbackUserdata userdata1 = 7134;
DawnCallbackUserdata userdata2 = 3144;
DawnCallbackUserdata userdata3 = 1130;
// Add callbacks in a non-monotonic order. They should still be called // Add callbacks in a non-monotonic order. They should still be called
// in order of increasing fence value. // in order of increasing fence value.
// Add multiple callbacks for the same value. // Add multiple callbacks for the same value.
dawnFenceOnCompletion(fence, 6, ToMockFenceOnCompletionCallback, userdata0); dawnFenceOnCompletion(fence, 6, ToMockFenceOnCompletionCallback, this + 0);
dawnFenceOnCompletion(fence, 2, ToMockFenceOnCompletionCallback, userdata1); dawnFenceOnCompletion(fence, 2, ToMockFenceOnCompletionCallback, this + 1);
dawnFenceOnCompletion(fence, 3, ToMockFenceOnCompletionCallback, userdata2); dawnFenceOnCompletion(fence, 3, ToMockFenceOnCompletionCallback, this + 2);
dawnFenceOnCompletion(fence, 2, ToMockFenceOnCompletionCallback, userdata3); dawnFenceOnCompletion(fence, 2, ToMockFenceOnCompletionCallback, this + 3);
Sequence s1, s2; Sequence s1, s2;
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata1)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 1))
.Times(1) .Times(1)
.InSequence(s1); .InSequence(s1);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata3)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 3))
.Times(1) .Times(1)
.InSequence(s2); .InSequence(s2);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata2)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 2))
.Times(1) .Times(1)
.InSequence(s1, s2); .InSequence(s1, s2);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback,
Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, userdata0)) Call(DAWN_FENCE_COMPLETION_STATUS_SUCCESS, this + 0))
.Times(1) .Times(1)
.InSequence(s1, s2); .InSequence(s1, s2);
@ -229,15 +217,13 @@ TEST_F(WireFenceTests, OnCompletionSynchronousValidationSuccess) {
// Without any flushes, errors should be generated when waiting on a value greater // Without any flushes, errors should be generated when waiting on a value greater
// than the last signaled value // than the last signaled value
TEST_F(WireFenceTests, OnCompletionSynchronousValidationError) { TEST_F(WireFenceTests, OnCompletionSynchronousValidationError) {
DawnCallbackUserdata userdata1 = 3817; dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, this + 1);
DawnCallbackUserdata userdata2 = 3857;
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata2);
EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_ERROR, userdata1)) EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_ERROR, this + 0))
.Times(1); .Times(1);
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata2)).Times(1); EXPECT_CALL(*mockDeviceErrorCallback, Call(_, this + 1)).Times(1);
dawnFenceOnCompletion(fence, 2u, ToMockFenceOnCompletionCallback, userdata1); dawnFenceOnCompletion(fence, 2u, ToMockFenceOnCompletionCallback, this + 0);
} }
// Check that the fence completed value is initialized // Check that the fence completed value is initialized
@ -263,11 +249,9 @@ TEST_F(WireFenceTests, GetCompletedValueNoUpdate) {
// Check that the callback is called with UNKNOWN when the fence is destroyed // Check that the callback is called with UNKNOWN when the fence is destroyed
// before the completed value is updated // before the completed value is updated
TEST_F(WireFenceTests, DestroyBeforeOnCompletionEnd) { TEST_F(WireFenceTests, DestroyBeforeOnCompletionEnd) {
DawnCallbackUserdata userdata = 8616;
dawnQueueSignal(queue, fence, 3u); dawnQueueSignal(queue, fence, 3u);
dawnFenceOnCompletion(fence, 2u, ToMockFenceOnCompletionCallback, userdata); dawnFenceOnCompletion(fence, 2u, ToMockFenceOnCompletionCallback, nullptr);
EXPECT_CALL(*mockFenceOnCompletionCallback, EXPECT_CALL(*mockFenceOnCompletionCallback, Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, _))
Call(DAWN_FENCE_COMPLETION_STATUS_UNKNOWN, userdata))
.Times(1); .Times(1);
} }
@ -278,10 +262,8 @@ TEST_F(WireFenceTests, SignalWrongQueue) {
EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue2)); EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue2));
FlushClient(); FlushClient();
DawnCallbackUserdata userdata = 1520; dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, nullptr);
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata); EXPECT_CALL(*mockDeviceErrorCallback, Call(_, _)).Times(1);
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1);
dawnQueueSignal(queue2, fence, 2u); // error dawnQueueSignal(queue2, fence, 2u); // error
} }
@ -292,10 +274,8 @@ TEST_F(WireFenceTests, SignalWrongQueueDoesNotUpdateValue) {
EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue2)); EXPECT_CALL(api, DeviceCreateQueue(apiDevice)).WillOnce(Return(apiQueue2));
FlushClient(); FlushClient();
DawnCallbackUserdata userdata = 1024; dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, nullptr);
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, userdata); EXPECT_CALL(*mockDeviceErrorCallback, Call(_, _)).Times(1);
EXPECT_CALL(*mockDeviceErrorCallback, Call(_, userdata)).Times(1);
dawnQueueSignal(queue2, fence, 2u); // error dawnQueueSignal(queue2, fence, 2u); // error
// Fence value should be unchanged. // Fence value should be unchanged.