Rename "buffer map read status" to "buffer map async status"

This is in preparation of MapWriteAsync that will use the same status
enum.
This commit is contained in:
Corentin Wallez 2018-03-20 19:48:54 -04:00 committed by Corentin Wallez
parent 2da19d5d6b
commit 8565e0056a
18 changed files with 68 additions and 64 deletions

View File

@ -37,7 +37,7 @@
typedef uint64_t nxtCallbackUserdata;
typedef void (*nxtDeviceErrorCallback)(const char* message, nxtCallbackUserdata userdata);
typedef void (*nxtBuilderErrorCallback)(nxtBuilderErrorStatus status, const char* message, nxtCallbackUserdata userdata1, nxtCallbackUserdata userdata2);
typedef void (*nxtBufferMapReadCallback)(nxtBufferMapReadStatus status, const void* data, nxtCallbackUserdata userdata);
typedef void (*nxtBufferMapReadCallback)(nxtBufferMapAsyncStatus status, const void* data, nxtCallbackUserdata userdata);
#ifdef __cplusplus
extern "C" {

View File

@ -72,7 +72,7 @@ void ProcTableAsClass::CallBuilderErrorCallback(void* builder , nxtBuilderErrorS
auto object = reinterpret_cast<ProcTableAsClass::Object*>(builder);
object->builderErrorCallback(status, message, object->userdata1, object->userdata2);
}
void ProcTableAsClass::CallMapReadCallback(nxtBuffer buffer, nxtBufferMapReadStatus status, const void* data) {
void ProcTableAsClass::CallMapReadCallback(nxtBuffer buffer, nxtBufferMapAsyncStatus status, const void* data) {
auto object = reinterpret_cast<ProcTableAsClass::Object*>(buffer);
object->mapReadCallback(status, data, object->userdata1);
}

View File

@ -67,7 +67,7 @@ class ProcTableAsClass {
// Calls the stored callbacks
void CallDeviceErrorCallback(nxtDevice device, const char* message);
void CallBuilderErrorCallback(void* builder , nxtBuilderErrorStatus status, const char* message);
void CallMapReadCallback(nxtBuffer buffer, nxtBufferMapReadStatus status, const void* data);
void CallMapReadCallback(nxtBuffer buffer, nxtBufferMapAsyncStatus status, const void* data);
struct Object {
ProcTableAsClass* procs = nullptr;

View File

@ -82,14 +82,14 @@ namespace wire {
~Buffer() {
//* Callbacks need to be fired in all cases, as they can handle freeing resources
//* so we call them with "Unknown" status.
ClearMapRequests(NXT_BUFFER_MAP_READ_STATUS_UNKNOWN);
ClearMapRequests(NXT_BUFFER_MAP_ASYNC_STATUS_UNKNOWN);
if (mappedData) {
free(mappedData);
}
}
void ClearMapRequests(nxtBufferMapReadStatus status) {
void ClearMapRequests(nxtBufferMapAsyncStatus status) {
for (auto& it : readRequests) {
it.second.callback(status, nullptr, it.second.userdata);
}
@ -364,7 +364,7 @@ namespace wire {
free(buffer->mappedData);
buffer->mappedData = nullptr;
}
buffer->ClearMapRequests(NXT_BUFFER_MAP_READ_STATUS_UNKNOWN);
buffer->ClearMapRequests(NXT_BUFFER_MAP_ASYNC_STATUS_UNKNOWN);
ClientBufferUnmap(buffer);
}
@ -536,7 +536,7 @@ namespace wire {
buffer->readRequests.erase(requestIt);
//* On success, we copy the data locally because the IPC buffer isn't valid outside of this function
if (cmd->status == NXT_BUFFER_MAP_READ_STATUS_SUCCESS) {
if (cmd->status == NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS) {
//* The server didn't send the right amount of data, this is an error and could cause
//* the application to crash if we did call the callback.
@ -550,9 +550,9 @@ namespace wire {
buffer->mappedData = malloc(request.size);
memcpy(buffer->mappedData, cmd->GetData(), request.size);
request.callback(static_cast<nxtBufferMapReadStatus>(cmd->status), buffer->mappedData, request.userdata);
request.callback(static_cast<nxtBufferMapAsyncStatus>(cmd->status), buffer->mappedData, request.userdata);
} else {
request.callback(static_cast<nxtBufferMapReadStatus>(cmd->status), nullptr, request.userdata);
request.callback(static_cast<nxtBufferMapAsyncStatus>(cmd->status), nullptr, request.userdata);
}
return true;

View File

@ -128,7 +128,7 @@ namespace wire {
void Forward{{type.name.CamelCase()}}ToClient(nxtBuilderErrorStatus status, const char* message, nxtCallbackUserdata userdata1, nxtCallbackUserdata userdata2);
{% endfor %}
void ForwardBufferMapReadAsync(nxtBufferMapReadStatus status, const void* ptr, nxtCallbackUserdata userdata);
void ForwardBufferMapReadAsync(nxtBufferMapAsyncStatus status, const void* ptr, nxtCallbackUserdata userdata);
class Server : public CommandHandler {
public:
@ -183,7 +183,7 @@ namespace wire {
}
{% endfor %}
void OnMapReadAsyncCallback(nxtBufferMapReadStatus status, const void* ptr, MapReadUserdata* data) {
void OnMapReadAsyncCallback(nxtBufferMapAsyncStatus status, const void* ptr, MapReadUserdata* data) {
ReturnBufferMapReadAsyncCallbackCmd cmd;
cmd.bufferId = data->bufferId;
cmd.bufferSerial = data->bufferSerial;
@ -191,14 +191,14 @@ namespace wire {
cmd.status = status;
cmd.dataLength = 0;
if (status == NXT_BUFFER_MAP_READ_STATUS_SUCCESS) {
if (status == NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS) {
cmd.dataLength = data->size;
}
auto allocCmd = reinterpret_cast<ReturnBufferMapReadAsyncCallbackCmd*>(GetCmdSpace(cmd.GetRequiredSize()));
*allocCmd = cmd;
if (status == NXT_BUFFER_MAP_READ_STATUS_SUCCESS) {
if (status == NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS) {
memcpy(allocCmd->GetData(), ptr, data->size);
}
@ -469,7 +469,7 @@ namespace wire {
if (!buffer->valid) {
//* Fake the buffer returning a failure, data will be freed in this call.
ForwardBufferMapReadAsync(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata);
ForwardBufferMapReadAsync(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata);
return true;
}
@ -493,7 +493,7 @@ namespace wire {
}
{% endfor %}
void ForwardBufferMapReadAsync(nxtBufferMapReadStatus status, const void* ptr, nxtCallbackUserdata userdata) {
void ForwardBufferMapReadAsync(nxtBufferMapAsyncStatus status, const void* ptr, nxtCallbackUserdata userdata) {
auto data = reinterpret_cast<MapReadUserdata*>(static_cast<uintptr_t>(userdata));
data->server->OnMapReadAsyncCallback(status, ptr, data);
}

View File

@ -257,7 +257,7 @@
"buffer map read callback": {
"category": "natively defined"
},
"buffer map read status": {
"buffer map async status": {
"category": "enum",
"values": [
{"value": 0, "name": "success"},

View File

@ -33,7 +33,7 @@ namespace backend {
BufferBase::~BufferBase() {
if (mIsMapped) {
CallMapReadCallback(mMapReadSerial, NXT_BUFFER_MAP_READ_STATUS_UNKNOWN, nullptr);
CallMapReadCallback(mMapReadSerial, NXT_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr);
}
}
@ -58,7 +58,7 @@ namespace backend {
}
void BufferBase::CallMapReadCallback(uint32_t serial,
nxtBufferMapReadStatus status,
nxtBufferMapAsyncStatus status,
const void* pointer) {
if (mMapReadCallback && serial == mMapReadSerial) {
// Tag the callback as fired before firing it, otherwise it could fire a second time if
@ -89,19 +89,19 @@ namespace backend {
nxtCallbackUserdata userdata) {
if (start + size > GetSize()) {
mDevice->HandleError("Buffer map read out of range");
callback(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata);
callback(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata);
return;
}
if (!(mCurrentUsage & nxt::BufferUsageBit::MapRead)) {
mDevice->HandleError("Buffer needs the map read usage bit");
callback(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata);
callback(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata);
return;
}
if (mIsMapped) {
mDevice->HandleError("Buffer already mapped");
callback(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata);
callback(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata);
return;
}
@ -121,7 +121,7 @@ namespace backend {
// A map request can only be called once, so this will fire only if the request wasn't
// completed before the Unmap
CallMapReadCallback(mMapReadSerial, NXT_BUFFER_MAP_READ_STATUS_UNKNOWN, nullptr);
CallMapReadCallback(mMapReadSerial, NXT_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr);
UnmapImpl();
mIsMapped = false;
}

View File

@ -52,7 +52,7 @@ namespace backend {
protected:
void CallMapReadCallback(uint32_t serial,
nxtBufferMapReadStatus status,
nxtBufferMapAsyncStatus status,
const void* pointer);
private:

View File

@ -145,7 +145,7 @@ namespace backend { namespace d3d12 {
}
void Buffer::OnMapReadCommandSerialFinished(uint32_t mapSerial, const void* data) {
CallMapReadCallback(mapSerial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data);
CallMapReadCallback(mapSerial, NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data);
}
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {

View File

@ -42,7 +42,7 @@ namespace backend { namespace metal {
void Buffer::OnMapReadCommandSerialFinished(uint32_t mapSerial, uint32_t offset) {
const char* data = reinterpret_cast<const char*>([mMtlBuffer contents]);
CallMapReadCallback(mapSerial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data + offset);
CallMapReadCallback(mapSerial, NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data + offset);
}
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {

View File

@ -132,7 +132,7 @@ namespace backend { namespace null {
}
void Buffer::MapReadOperationCompleted(uint32_t serial, const void* ptr) {
CallMapReadCallback(serial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, ptr);
CallMapReadCallback(serial, NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, ptr);
}
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {

View File

@ -42,7 +42,7 @@ namespace backend { namespace opengl {
// instead?
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
void* data = glMapBufferRange(GL_ARRAY_BUFFER, start, count, GL_MAP_READ_BIT);
CallMapReadCallback(serial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data);
CallMapReadCallback(serial, NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data);
}
void Buffer::UnmapImpl() {

View File

@ -151,7 +151,7 @@ namespace backend { namespace vulkan {
}
void Buffer::OnMapReadCommandSerialFinished(uint32_t mapSerial, const void* data) {
CallMapReadCallback(mapSerial, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, data);
CallMapReadCallback(mapSerial, NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data);
}
VkBuffer Buffer::GetHandle() const {

View File

@ -276,8 +276,10 @@ void NXTTest::MapSlotsSynchronously() {
}
// static
void NXTTest::SlotMapReadCallback(nxtBufferMapReadStatus status, const void* data, nxtCallbackUserdata userdata_) {
NXT_ASSERT(status == NXT_BUFFER_MAP_READ_STATUS_SUCCESS);
void NXTTest::SlotMapReadCallback(nxtBufferMapAsyncStatus status,
const void* data,
nxtCallbackUserdata userdata_) {
NXT_ASSERT(status == NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS);
auto userdata = reinterpret_cast<MapReadUserdata*>(static_cast<uintptr_t>(userdata_));
userdata->test->mReadbackSlots[userdata->slot].mappedData = data;

View File

@ -98,7 +98,9 @@ class NXTTest : public ::testing::TestWithParam<BackendType> {
// Maps all the buffers and fill ReadbackSlot::mappedData
void MapSlotsSynchronously();
static void SlotMapReadCallback(nxtBufferMapReadStatus status, const void* data, nxtCallbackUserdata userdata);
static void SlotMapReadCallback(nxtBufferMapAsyncStatus status,
const void* data,
nxtCallbackUserdata userdata);
size_t mNumPendingMapOperations = 0;
// Reserve space where the data for an expectation can be copied

View File

@ -19,8 +19,8 @@
class BufferMapReadTests : public NXTTest {
protected:
static void MapReadCallback(nxtBufferMapReadStatus status, const void* data, nxtCallbackUserdata userdata) {
ASSERT_EQ(NXT_BUFFER_MAP_READ_STATUS_SUCCESS, status);
static void MapReadCallback(nxtBufferMapAsyncStatus status, const void* data, nxtCallbackUserdata userdata) {
ASSERT_EQ(NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status);
ASSERT_NE(nullptr, data);
auto test = reinterpret_cast<BufferMapReadTests*>(static_cast<uintptr_t>(userdata));

View File

@ -43,11 +43,11 @@ static void ToMockBuilderErrorCallback(nxtBuilderErrorStatus status, const char*
class MockBufferMapReadCallback {
public:
MOCK_METHOD3(Call, void(nxtBufferMapReadStatus status, const uint32_t* ptr, nxtCallbackUserdata userdata));
MOCK_METHOD3(Call, void(nxtBufferMapAsyncStatus status, const uint32_t* ptr, nxtCallbackUserdata userdata));
};
static MockBufferMapReadCallback* mockBufferMapReadCallback = nullptr;
static void ToMockBufferMapReadCallback(nxtBufferMapReadStatus status, const void* ptr, nxtCallbackUserdata userdata) {
static void ToMockBufferMapReadCallback(nxtBufferMapAsyncStatus status, const void* ptr, nxtCallbackUserdata userdata) {
// Assume the data is uint32_t to make writing matchers easier
mockBufferMapReadCallback->Call(status, reinterpret_cast<const uint32_t*>(ptr), userdata);
}
@ -604,12 +604,12 @@ TEST_F(WireBufferMappingTests, MappingSuccessBuffer) {
uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, &bufferContent);
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, &bufferContent);
}));
FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
.Times(1);
FlushServer();
@ -628,12 +628,12 @@ TEST_F(WireBufferMappingTests, ErrorWhileMapping) {
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr);
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr);
}));
FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
.Times(1);
FlushServer();
@ -646,7 +646,7 @@ TEST_F(WireBufferMappingTests, MappingErrorBuffer) {
FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
.Times(1);
FlushServer();
@ -661,7 +661,7 @@ TEST_F(WireBufferMappingTests, DestroyBeforeRequestEnd) {
nxtCallbackUserdata userdata = 8656;
nxtBufferMapReadAsync(errorBuffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_UNKNOWN, nullptr, userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
.Times(1);
nxtBufferRelease(errorBuffer);
@ -675,13 +675,13 @@ TEST_F(WireBufferMappingTests, UnmapCalledTooEarly) {
uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, &bufferContent);
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, &bufferContent);
}));
FlushClient();
// Oh no! We are calling Unmap too early!
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_UNKNOWN, nullptr, userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
.Times(1);
nxtBufferUnmap(buffer);
@ -698,13 +698,13 @@ TEST_F(WireBufferMappingTests, MappingErrorWhileAlreadyMappedGetsNullptr) {
uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, &bufferContent);
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, &bufferContent);
}))
.RetiresOnSaturation();
FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
.Times(1);
FlushServer();
@ -714,12 +714,12 @@ TEST_F(WireBufferMappingTests, MappingErrorWhileAlreadyMappedGetsNullptr) {
nxtBufferMapReadAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr);
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr);
}));
FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
.Times(1);
FlushServer();
@ -733,12 +733,12 @@ TEST_F(WireBufferMappingTests, UnmapInsideMapReadCallback) {
uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, &bufferContent);
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, &bufferContent);
}));
FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
.WillOnce(InvokeWithoutArgs([&]() {
nxtBufferUnmap(buffer);
}));
@ -759,12 +759,12 @@ TEST_F(WireBufferMappingTests, DestroyInsideMapReadCallback) {
uint32_t bufferContent = 31337;
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
.WillOnce(InvokeWithoutArgs([&]() {
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_READ_STATUS_SUCCESS, &bufferContent);
api.CallMapReadCallback(apiBuffer, NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, &bufferContent);
}));
FlushClient();
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
.WillOnce(InvokeWithoutArgs([&]() {
nxtBufferRelease(buffer);
}));

View File

@ -20,11 +20,11 @@ using namespace testing;
class MockBufferMapReadCallback {
public:
MOCK_METHOD3(Call, void(nxtBufferMapReadStatus status, const uint32_t* ptr, nxtCallbackUserdata userdata));
MOCK_METHOD3(Call, void(nxtBufferMapAsyncStatus status, const uint32_t* ptr, nxtCallbackUserdata userdata));
};
static MockBufferMapReadCallback* mockBufferMapReadCallback = nullptr;
static void ToMockBufferMapReadCallback(nxtBufferMapReadStatus status, const void* ptr, nxtCallbackUserdata userdata) {
static void ToMockBufferMapReadCallback(nxtBufferMapAsyncStatus status, const void* ptr, nxtCallbackUserdata userdata) {
// Assume the data is uint32_t to make writing matchers easier
mockBufferMapReadCallback->Call(status, reinterpret_cast<const uint32_t*>(ptr), userdata);
}
@ -184,7 +184,7 @@ TEST_F(BufferValidationTest, MapReadSuccess) {
nxt::CallbackUserdata userdata = 40598;
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_SUCCESS, Ne(nullptr), userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata))
.Times(1);
queue.Submit(0, nullptr);
@ -196,7 +196,7 @@ TEST_F(BufferValidationTest, MapReadOutOfRange) {
nxt::Buffer buf = CreateMapReadBuffer(4);
nxt::CallbackUserdata userdata = 40599;
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
.Times(1);
ASSERT_DEVICE_ERROR(buf.MapReadAsync(0, 5, ToMockBufferMapReadCallback, userdata));
@ -211,7 +211,7 @@ TEST_F(BufferValidationTest, MapReadWrongUsage) {
.GetResult();
nxt::CallbackUserdata userdata = 40600;
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
.Times(1);
ASSERT_DEVICE_ERROR(buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata));
@ -223,11 +223,11 @@ TEST_F(BufferValidationTest, MapReadAlreadyMapped) {
nxt::CallbackUserdata userdata1 = 40601;
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata1);
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_SUCCESS, Ne(nullptr), userdata1))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata1))
.Times(1);
nxt::CallbackUserdata userdata2 = 40602;
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata2))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata2))
.Times(1);
ASSERT_DEVICE_ERROR(buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata2));
@ -241,7 +241,7 @@ TEST_F(BufferValidationTest, MapReadUnmapBeforeResult) {
nxt::CallbackUserdata userdata = 40603;
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_UNKNOWN, nullptr, userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
.Times(1);
buf.Unmap();
@ -260,7 +260,7 @@ TEST_F(BufferValidationTest, DISABLED_MapReadDestroyBeforeResult) {
nxt::CallbackUserdata userdata = 40604;
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_UNKNOWN, nullptr, userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
.Times(1);
}
@ -277,7 +277,7 @@ TEST_F(BufferValidationTest, MapReadUnmapBeforeResultThenMapAgain) {
nxt::CallbackUserdata userdata = 40605;
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_UNKNOWN, nullptr, userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
.Times(1);
buf.Unmap();
@ -285,7 +285,7 @@ TEST_F(BufferValidationTest, MapReadUnmapBeforeResultThenMapAgain) {
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_SUCCESS, Ne(nullptr), userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata))
.Times(1);
queue.Submit(0, nullptr);
}
@ -297,7 +297,7 @@ TEST_F(BufferValidationTest, UnmapInsideMapReadCallback) {
nxt::CallbackUserdata userdata = 40678;
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_SUCCESS, Ne(nullptr), userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata))
.WillOnce(InvokeWithoutArgs([&]() {
buf.Unmap();
}));
@ -312,7 +312,7 @@ TEST_F(BufferValidationTest, DestroyInsideMapReadCallback) {
nxt::CallbackUserdata userdata = 40679;
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_READ_STATUS_SUCCESS, Ne(nullptr), userdata))
EXPECT_CALL(*mockBufferMapReadCallback, Call(NXT_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata))
.WillOnce(InvokeWithoutArgs([&]() {
buf = nxt::Buffer();
}));