Remove |start| and |size| from buffer mapping
This is part of making buffer mapping match WebGPU Bug: dawn:7 Change-Id: Ia97c872e398112aef0f93c98618c8a7f3ff0c19a Reviewed-on: https://dawn-review.googlesource.com/c/4580 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
parent
1198270483
commit
1541c8ba7a
|
@ -164,21 +164,15 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"_comment": "Contrary to set sub data, this is in char size",
|
||||
"name": "map read async",
|
||||
"args": [
|
||||
{"name": "start", "type": "uint32_t"},
|
||||
{"name": "size", "type": "uint32_t"},
|
||||
{"name": "callback", "type": "buffer map read callback"},
|
||||
{"name": "userdata", "type": "callback userdata"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"_comment": "Contrary to set sub data, this is in char size",
|
||||
"name": "map write async",
|
||||
"args": [
|
||||
{"name": "start", "type": "uint32_t"},
|
||||
{"name": "size", "type": "uint32_t"},
|
||||
{"name": "callback", "type": "buffer map write callback"},
|
||||
{"name": "userdata", "type": "callback userdata"}
|
||||
]
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
"buffer map async": [
|
||||
{ "name": "buffer id", "type": "ObjectId" },
|
||||
{ "name": "request serial", "type": "uint32_t" },
|
||||
{ "name": "start", "type": "uint32_t" },
|
||||
{ "name": "size", "type": "uint32_t" },
|
||||
{ "name": "is write", "type": "bool" }
|
||||
],
|
||||
"buffer update mapped data": [
|
||||
|
@ -43,7 +41,8 @@
|
|||
"buffer map write async callback": [
|
||||
{ "name": "buffer", "type": "ObjectHandle", "handle_type": "buffer" },
|
||||
{ "name": "request serial", "type": "uint32_t" },
|
||||
{ "name": "status", "type": "uint32_t" }
|
||||
{ "name": "status", "type": "uint32_t" },
|
||||
{ "name": "data length", "type": "uint32_t" }
|
||||
],
|
||||
"device error callback": [
|
||||
{ "name": "message", "type": "char", "annotation": "const*", "length": "strlen" }
|
||||
|
|
|
@ -51,8 +51,8 @@
|
|||
typedef uint64_t dawnCallbackUserdata;
|
||||
typedef void (*dawnDeviceErrorCallback)(const char* message, dawnCallbackUserdata userdata);
|
||||
typedef void (*dawnBuilderErrorCallback)(dawnBuilderErrorStatus status, const char* message, dawnCallbackUserdata userdata1, dawnCallbackUserdata userdata2);
|
||||
typedef void (*dawnBufferMapReadCallback)(dawnBufferMapAsyncStatus status, const void* data, dawnCallbackUserdata userdata);
|
||||
typedef void (*dawnBufferMapWriteCallback)(dawnBufferMapAsyncStatus status, void* data, dawnCallbackUserdata userdata);
|
||||
typedef void (*dawnBufferMapReadCallback)(dawnBufferMapAsyncStatus status, const void* data, uint32_t dataLength, dawnCallbackUserdata userdata);
|
||||
typedef void (*dawnBufferMapWriteCallback)(dawnBufferMapAsyncStatus status, void* data, uint32_t dataLength, dawnCallbackUserdata userdata);
|
||||
typedef void (*dawnFenceOnCompletionCallback)(dawnFenceCompletionStatus status,
|
||||
dawnCallbackUserdata userdata);
|
||||
|
||||
|
|
|
@ -56,20 +56,20 @@ void ProcTableAsClass::DeviceSetErrorCallback(dawnDevice self, dawnDeviceErrorCa
|
|||
OnDeviceSetErrorCallback(self, callback, userdata);
|
||||
}
|
||||
|
||||
void ProcTableAsClass::BufferMapReadAsync(dawnBuffer self, uint32_t start, uint32_t size, dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata) {
|
||||
void ProcTableAsClass::BufferMapReadAsync(dawnBuffer self, dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata) {
|
||||
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
||||
object->mapReadCallback = callback;
|
||||
object->userdata1 = userdata;
|
||||
|
||||
OnBufferMapReadAsyncCallback(self, start, size, callback, userdata);
|
||||
OnBufferMapReadAsyncCallback(self, callback, userdata);
|
||||
}
|
||||
|
||||
void ProcTableAsClass::BufferMapWriteAsync(dawnBuffer self, uint32_t start, uint32_t size, dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata) {
|
||||
void ProcTableAsClass::BufferMapWriteAsync(dawnBuffer self, dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata) {
|
||||
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
||||
object->mapWriteCallback = callback;
|
||||
object->userdata1 = userdata;
|
||||
|
||||
OnBufferMapWriteAsyncCallback(self, start, size, callback, userdata);
|
||||
OnBufferMapWriteAsyncCallback(self, callback, userdata);
|
||||
}
|
||||
|
||||
void ProcTableAsClass::FenceOnCompletion(dawnFence self,
|
||||
|
@ -91,14 +91,14 @@ void ProcTableAsClass::CallBuilderErrorCallback(void* builder , dawnBuilderError
|
|||
auto object = reinterpret_cast<ProcTableAsClass::Object*>(builder);
|
||||
object->builderErrorCallback(status, message, object->userdata1, object->userdata2);
|
||||
}
|
||||
void ProcTableAsClass::CallMapReadCallback(dawnBuffer buffer, dawnBufferMapAsyncStatus status, const void* data) {
|
||||
void ProcTableAsClass::CallMapReadCallback(dawnBuffer buffer, dawnBufferMapAsyncStatus status, const void* data, uint32_t dataLength) {
|
||||
auto object = reinterpret_cast<ProcTableAsClass::Object*>(buffer);
|
||||
object->mapReadCallback(status, data, object->userdata1);
|
||||
object->mapReadCallback(status, data, dataLength, object->userdata1);
|
||||
}
|
||||
|
||||
void ProcTableAsClass::CallMapWriteCallback(dawnBuffer buffer, dawnBufferMapAsyncStatus status, void* data) {
|
||||
void ProcTableAsClass::CallMapWriteCallback(dawnBuffer buffer, dawnBufferMapAsyncStatus status, void* data, uint32_t dataLength) {
|
||||
auto object = reinterpret_cast<ProcTableAsClass::Object*>(buffer);
|
||||
object->mapWriteCallback(status, data, object->userdata1);
|
||||
object->mapWriteCallback(status, data, dataLength, object->userdata1);
|
||||
}
|
||||
|
||||
void ProcTableAsClass::CallFenceOnCompletionCallback(dawnFence fence,
|
||||
|
|
|
@ -57,8 +57,8 @@ class ProcTableAsClass {
|
|||
|
||||
// Stores callback and userdata and calls the On* methods
|
||||
void DeviceSetErrorCallback(dawnDevice self, dawnDeviceErrorCallback callback, dawnCallbackUserdata userdata);
|
||||
void BufferMapReadAsync(dawnBuffer self, uint32_t start, uint32_t size, dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata);
|
||||
void BufferMapWriteAsync(dawnBuffer self, uint32_t start, uint32_t size, dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata);
|
||||
void BufferMapReadAsync(dawnBuffer self, dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata);
|
||||
void BufferMapWriteAsync(dawnBuffer self, dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata);
|
||||
void FenceOnCompletion(dawnFence self,
|
||||
uint64_t value,
|
||||
dawnFenceOnCompletionCallback callback,
|
||||
|
@ -67,8 +67,8 @@ class ProcTableAsClass {
|
|||
// Special cased mockable methods
|
||||
virtual void OnDeviceSetErrorCallback(dawnDevice device, dawnDeviceErrorCallback callback, dawnCallbackUserdata userdata) = 0;
|
||||
virtual void OnBuilderSetErrorCallback(dawnBufferBuilder builder, dawnBuilderErrorCallback callback, dawnCallbackUserdata userdata1, dawnCallbackUserdata userdata2) = 0;
|
||||
virtual void OnBufferMapReadAsyncCallback(dawnBuffer buffer, uint32_t start, uint32_t size, dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata) = 0;
|
||||
virtual void OnBufferMapWriteAsyncCallback(dawnBuffer buffer, uint32_t start, uint32_t size, dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata) = 0;
|
||||
virtual void OnBufferMapReadAsyncCallback(dawnBuffer buffer, dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata) = 0;
|
||||
virtual void OnBufferMapWriteAsyncCallback(dawnBuffer buffer, dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata) = 0;
|
||||
virtual void OnFenceOnCompletionCallback(dawnFence fence,
|
||||
uint64_t value,
|
||||
dawnFenceOnCompletionCallback callback,
|
||||
|
@ -77,8 +77,8 @@ class ProcTableAsClass {
|
|||
// Calls the stored callbacks
|
||||
void CallDeviceErrorCallback(dawnDevice device, const char* message);
|
||||
void CallBuilderErrorCallback(void* builder , dawnBuilderErrorStatus status, const char* message);
|
||||
void CallMapReadCallback(dawnBuffer buffer, dawnBufferMapAsyncStatus status, const void* data);
|
||||
void CallMapWriteCallback(dawnBuffer buffer, dawnBufferMapAsyncStatus status, void* data);
|
||||
void CallMapReadCallback(dawnBuffer buffer, dawnBufferMapAsyncStatus status, const void* data, uint32_t dataLength);
|
||||
void CallMapWriteCallback(dawnBuffer buffer, dawnBufferMapAsyncStatus status, void* data, uint32_t dataLength);
|
||||
void CallFenceOnCompletionCallback(dawnFence fence, dawnFenceCompletionStatus status);
|
||||
|
||||
struct Object {
|
||||
|
@ -119,8 +119,8 @@ class MockProcTable : public ProcTableAsClass {
|
|||
|
||||
MOCK_METHOD3(OnDeviceSetErrorCallback, void(dawnDevice device, dawnDeviceErrorCallback callback, dawnCallbackUserdata userdata));
|
||||
MOCK_METHOD4(OnBuilderSetErrorCallback, void(dawnBufferBuilder builder, dawnBuilderErrorCallback callback, dawnCallbackUserdata userdata1, dawnCallbackUserdata userdata2));
|
||||
MOCK_METHOD5(OnBufferMapReadAsyncCallback, void(dawnBuffer buffer, uint32_t start, uint32_t size, dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata));
|
||||
MOCK_METHOD5(OnBufferMapWriteAsyncCallback, void(dawnBuffer buffer, uint32_t start, uint32_t size, dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata));
|
||||
MOCK_METHOD3(OnBufferMapReadAsyncCallback, void(dawnBuffer buffer, dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata));
|
||||
MOCK_METHOD3(OnBufferMapWriteAsyncCallback, void(dawnBuffer buffer, dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata));
|
||||
MOCK_METHOD4(OnFenceOnCompletionCallback,
|
||||
void(dawnFence fence,
|
||||
uint64_t value,
|
||||
|
|
|
@ -37,10 +37,10 @@ namespace dawn_native {
|
|||
UNREACHABLE();
|
||||
return {};
|
||||
}
|
||||
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) override {
|
||||
void MapReadAsyncImpl(uint32_t serial) override {
|
||||
UNREACHABLE();
|
||||
}
|
||||
void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) override {
|
||||
void MapWriteAsyncImpl(uint32_t serial) override {
|
||||
UNREACHABLE();
|
||||
}
|
||||
void UnmapImpl() override {
|
||||
|
@ -90,8 +90,8 @@ namespace dawn_native {
|
|||
BufferBase::~BufferBase() {
|
||||
if (mState == BufferState::Mapped) {
|
||||
ASSERT(!IsError());
|
||||
CallMapReadCallback(mMapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr);
|
||||
CallMapWriteCallback(mMapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr);
|
||||
CallMapReadCallback(mMapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u);
|
||||
CallMapWriteCallback(mMapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,31 +125,31 @@ namespace dawn_native {
|
|||
|
||||
void BufferBase::CallMapReadCallback(uint32_t serial,
|
||||
dawnBufferMapAsyncStatus status,
|
||||
const void* pointer) {
|
||||
const void* pointer,
|
||||
uint32_t dataLength) {
|
||||
ASSERT(!IsError());
|
||||
|
||||
if (mMapReadCallback != nullptr && serial == mMapSerial) {
|
||||
ASSERT(mMapWriteCallback == nullptr);
|
||||
// Tag the callback as fired before firing it, otherwise it could fire a second time if
|
||||
// for example buffer.Unmap() is called inside the application-provided callback.
|
||||
dawnBufferMapReadCallback callback = mMapReadCallback;
|
||||
mMapReadCallback = nullptr;
|
||||
callback(status, pointer, mMapUserdata);
|
||||
callback(status, pointer, dataLength, mMapUserdata);
|
||||
}
|
||||
}
|
||||
|
||||
void BufferBase::CallMapWriteCallback(uint32_t serial,
|
||||
dawnBufferMapAsyncStatus status,
|
||||
void* pointer) {
|
||||
void* pointer,
|
||||
uint32_t dataLength) {
|
||||
ASSERT(!IsError());
|
||||
|
||||
if (mMapWriteCallback != nullptr && serial == mMapSerial) {
|
||||
ASSERT(mMapReadCallback == nullptr);
|
||||
// Tag the callback as fired before firing it, otherwise it could fire a second time if
|
||||
// for example buffer.Unmap() is called inside the application-provided callback.
|
||||
dawnBufferMapWriteCallback callback = mMapWriteCallback;
|
||||
mMapWriteCallback = nullptr;
|
||||
callback(status, pointer, mMapUserdata);
|
||||
callback(status, pointer, dataLength, mMapUserdata);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,12 +164,10 @@ namespace dawn_native {
|
|||
}
|
||||
}
|
||||
|
||||
void BufferBase::MapReadAsync(uint32_t start,
|
||||
uint32_t size,
|
||||
dawnBufferMapReadCallback callback,
|
||||
void BufferBase::MapReadAsync(dawnBufferMapReadCallback callback,
|
||||
dawnCallbackUserdata userdata) {
|
||||
if (GetDevice()->ConsumedError(ValidateMap(start, size, dawn::BufferUsageBit::MapRead))) {
|
||||
callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata);
|
||||
if (GetDevice()->ConsumedError(ValidateMap(dawn::BufferUsageBit::MapRead))) {
|
||||
callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata);
|
||||
return;
|
||||
}
|
||||
ASSERT(!IsError());
|
||||
|
@ -182,15 +180,13 @@ namespace dawn_native {
|
|||
mMapUserdata = userdata;
|
||||
mState = BufferState::Mapped;
|
||||
|
||||
MapReadAsyncImpl(mMapSerial, start, size);
|
||||
MapReadAsyncImpl(mMapSerial);
|
||||
}
|
||||
|
||||
void BufferBase::MapWriteAsync(uint32_t start,
|
||||
uint32_t size,
|
||||
dawnBufferMapWriteCallback callback,
|
||||
void BufferBase::MapWriteAsync(dawnBufferMapWriteCallback callback,
|
||||
dawnCallbackUserdata userdata) {
|
||||
if (GetDevice()->ConsumedError(ValidateMap(start, size, dawn::BufferUsageBit::MapWrite))) {
|
||||
callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata);
|
||||
if (GetDevice()->ConsumedError(ValidateMap(dawn::BufferUsageBit::MapWrite))) {
|
||||
callback(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata);
|
||||
return;
|
||||
}
|
||||
ASSERT(!IsError());
|
||||
|
@ -203,7 +199,7 @@ namespace dawn_native {
|
|||
mMapUserdata = userdata;
|
||||
mState = BufferState::Mapped;
|
||||
|
||||
MapWriteAsyncImpl(mMapSerial, start, size);
|
||||
MapWriteAsyncImpl(mMapSerial);
|
||||
}
|
||||
|
||||
void BufferBase::Destroy() {
|
||||
|
@ -226,8 +222,8 @@ namespace dawn_native {
|
|||
|
||||
// A map request can only be called once, so this will fire only if the request wasn't
|
||||
// completed before the Unmap
|
||||
CallMapReadCallback(mMapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr);
|
||||
CallMapWriteCallback(mMapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr);
|
||||
CallMapReadCallback(mMapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u);
|
||||
CallMapWriteCallback(mMapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u);
|
||||
UnmapImpl();
|
||||
mState = BufferState::Unmapped;
|
||||
mMapReadCallback = nullptr;
|
||||
|
@ -262,20 +258,9 @@ namespace dawn_native {
|
|||
return {};
|
||||
}
|
||||
|
||||
MaybeError BufferBase::ValidateMap(uint32_t start,
|
||||
uint32_t size,
|
||||
dawn::BufferUsageBit requiredUsage) const {
|
||||
MaybeError BufferBase::ValidateMap(dawn::BufferUsageBit requiredUsage) const {
|
||||
DAWN_TRY(GetDevice()->ValidateObject(this));
|
||||
|
||||
if (size > GetSize()) {
|
||||
return DAWN_VALIDATION_ERROR("Buffer mapping with too big a region");
|
||||
}
|
||||
|
||||
// Note that no overflow can happen because we already checked for GetSize() >= size
|
||||
if (start > GetSize() - size) {
|
||||
return DAWN_VALIDATION_ERROR("Buffer mapping out of range");
|
||||
}
|
||||
|
||||
if (mState == BufferState::Destroyed) {
|
||||
return DAWN_VALIDATION_ERROR("Buffer is destroyed");
|
||||
}
|
||||
|
|
|
@ -54,14 +54,8 @@ namespace dawn_native {
|
|||
|
||||
// Dawn API
|
||||
void SetSubData(uint32_t start, uint32_t count, const uint8_t* data);
|
||||
void MapReadAsync(uint32_t start,
|
||||
uint32_t size,
|
||||
dawnBufferMapReadCallback callback,
|
||||
dawnCallbackUserdata userdata);
|
||||
void MapWriteAsync(uint32_t start,
|
||||
uint32_t size,
|
||||
dawnBufferMapWriteCallback callback,
|
||||
dawnCallbackUserdata userdata);
|
||||
void MapReadAsync(dawnBufferMapReadCallback callback, dawnCallbackUserdata userdata);
|
||||
void MapWriteAsync(dawnBufferMapWriteCallback callback, dawnCallbackUserdata userdata);
|
||||
void Unmap();
|
||||
void Destroy();
|
||||
|
||||
|
@ -70,19 +64,21 @@ namespace dawn_native {
|
|||
|
||||
void CallMapReadCallback(uint32_t serial,
|
||||
dawnBufferMapAsyncStatus status,
|
||||
const void* pointer);
|
||||
void CallMapWriteCallback(uint32_t serial, dawnBufferMapAsyncStatus status, void* pointer);
|
||||
const void* pointer,
|
||||
uint32_t dataLength);
|
||||
void CallMapWriteCallback(uint32_t serial,
|
||||
dawnBufferMapAsyncStatus status,
|
||||
void* pointer,
|
||||
uint32_t dataLength);
|
||||
|
||||
private:
|
||||
virtual MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const uint8_t* data) = 0;
|
||||
virtual void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) = 0;
|
||||
virtual void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) = 0;
|
||||
virtual void MapReadAsyncImpl(uint32_t serial) = 0;
|
||||
virtual void MapWriteAsyncImpl(uint32_t serial) = 0;
|
||||
virtual void UnmapImpl() = 0;
|
||||
|
||||
MaybeError ValidateSetSubData(uint32_t start, uint32_t count) const;
|
||||
MaybeError ValidateMap(uint32_t start,
|
||||
uint32_t size,
|
||||
dawn::BufferUsageBit requiredUsage) const;
|
||||
MaybeError ValidateMap(dawn::BufferUsageBit requiredUsage) const;
|
||||
MaybeError ValidateUnmap() const;
|
||||
MaybeError ValidateDestroy() const;
|
||||
|
||||
|
|
|
@ -155,9 +155,9 @@ namespace dawn_native { namespace d3d12 {
|
|||
|
||||
void Buffer::OnMapCommandSerialFinished(uint32_t mapSerial, void* data, bool isWrite) {
|
||||
if (isWrite) {
|
||||
CallMapWriteCallback(mapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data);
|
||||
CallMapWriteCallback(mapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data, GetSize());
|
||||
} else {
|
||||
CallMapReadCallback(mapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data);
|
||||
CallMapReadCallback(mapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data, GetSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,27 +179,27 @@ namespace dawn_native { namespace d3d12 {
|
|||
return {};
|
||||
}
|
||||
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial) {
|
||||
mWrittenMappedRange = {};
|
||||
D3D12_RANGE readRange = {start, start + count};
|
||||
D3D12_RANGE readRange = {0, GetSize()};
|
||||
char* data = nullptr;
|
||||
ASSERT_SUCCESS(mResource->Map(0, &readRange, reinterpret_cast<void**>(&data)));
|
||||
|
||||
// There is no need to transition the resource to a new state: D3D12 seems to make the GPU
|
||||
// writes available when the fence is passed.
|
||||
MapRequestTracker* tracker = ToBackend(GetDevice())->GetMapRequestTracker();
|
||||
tracker->Track(this, serial, data + start, false);
|
||||
tracker->Track(this, serial, data, false);
|
||||
}
|
||||
|
||||
void Buffer::MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
|
||||
mWrittenMappedRange = {start, start + count};
|
||||
void Buffer::MapWriteAsyncImpl(uint32_t serial) {
|
||||
mWrittenMappedRange = {0, GetSize()};
|
||||
char* data = nullptr;
|
||||
ASSERT_SUCCESS(mResource->Map(0, &mWrittenMappedRange, reinterpret_cast<void**>(&data)));
|
||||
|
||||
// There is no need to transition the resource to a new state: D3D12 seems to make the CPU
|
||||
// writes available on queue submission.
|
||||
MapRequestTracker* tracker = ToBackend(GetDevice())->GetMapRequestTracker();
|
||||
tracker->Track(this, serial, data + start, true);
|
||||
tracker->Track(this, serial, data, true);
|
||||
}
|
||||
|
||||
void Buffer::UnmapImpl() {
|
||||
|
|
|
@ -40,8 +40,8 @@ namespace dawn_native { namespace d3d12 {
|
|||
private:
|
||||
// Dawn API
|
||||
MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const uint8_t* data) override;
|
||||
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
|
||||
void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
|
||||
void MapReadAsyncImpl(uint32_t serial) override;
|
||||
void MapWriteAsyncImpl(uint32_t serial) override;
|
||||
void UnmapImpl() override;
|
||||
|
||||
// TODO(b-brber): Remove once alignment constraint is added to validation (dawn:73).
|
||||
|
|
|
@ -31,12 +31,12 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
id<MTLBuffer> GetMTLBuffer();
|
||||
|
||||
void OnMapCommandSerialFinished(uint32_t mapSerial, uint32_t offset, bool isWrite);
|
||||
void OnMapCommandSerialFinished(uint32_t mapSerial, bool isWrite);
|
||||
|
||||
private:
|
||||
MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const uint8_t* data) override;
|
||||
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
|
||||
void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
|
||||
void MapReadAsyncImpl(uint32_t serial) override;
|
||||
void MapWriteAsyncImpl(uint32_t serial) override;
|
||||
void UnmapImpl() override;
|
||||
|
||||
id<MTLBuffer> mMtlBuffer = nil;
|
||||
|
@ -47,7 +47,7 @@ namespace dawn_native { namespace metal {
|
|||
MapRequestTracker(Device* device);
|
||||
~MapRequestTracker();
|
||||
|
||||
void Track(Buffer* buffer, uint32_t mapSerial, uint32_t offset, bool isWrite);
|
||||
void Track(Buffer* buffer, uint32_t mapSerial, bool isWrite);
|
||||
void Tick(Serial finishedSerial);
|
||||
|
||||
private:
|
||||
|
@ -56,7 +56,6 @@ namespace dawn_native { namespace metal {
|
|||
struct Request {
|
||||
Ref<Buffer> buffer;
|
||||
uint32_t mapSerial;
|
||||
uint32_t offset;
|
||||
bool isWrite;
|
||||
};
|
||||
SerialQueue<Request> mInflightRequests;
|
||||
|
|
|
@ -40,12 +40,12 @@ namespace dawn_native { namespace metal {
|
|||
return mMtlBuffer;
|
||||
}
|
||||
|
||||
void Buffer::OnMapCommandSerialFinished(uint32_t mapSerial, uint32_t offset, bool isWrite) {
|
||||
void Buffer::OnMapCommandSerialFinished(uint32_t mapSerial, bool isWrite) {
|
||||
char* data = reinterpret_cast<char*>([mMtlBuffer contents]);
|
||||
if (isWrite) {
|
||||
CallMapWriteCallback(mapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data + offset);
|
||||
CallMapWriteCallback(mapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data, GetSize());
|
||||
} else {
|
||||
CallMapReadCallback(mapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data + offset);
|
||||
CallMapReadCallback(mapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data, GetSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,14 +55,14 @@ namespace dawn_native { namespace metal {
|
|||
return {};
|
||||
}
|
||||
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t) {
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial) {
|
||||
MapRequestTracker* tracker = ToBackend(GetDevice())->GetMapTracker();
|
||||
tracker->Track(this, serial, start, false);
|
||||
tracker->Track(this, serial, false);
|
||||
}
|
||||
|
||||
void Buffer::MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t) {
|
||||
void Buffer::MapWriteAsyncImpl(uint32_t serial) {
|
||||
MapRequestTracker* tracker = ToBackend(GetDevice())->GetMapTracker();
|
||||
tracker->Track(this, serial, start, true);
|
||||
tracker->Track(this, serial, true);
|
||||
}
|
||||
|
||||
void Buffer::UnmapImpl() {
|
||||
|
@ -78,12 +78,10 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
void MapRequestTracker::Track(Buffer* buffer,
|
||||
uint32_t mapSerial,
|
||||
uint32_t offset,
|
||||
bool isWrite) {
|
||||
Request request;
|
||||
request.buffer = buffer;
|
||||
request.mapSerial = mapSerial;
|
||||
request.offset = offset;
|
||||
request.isWrite = isWrite;
|
||||
|
||||
mInflightRequests.Enqueue(std::move(request), mDevice->GetPendingCommandSerial());
|
||||
|
@ -91,8 +89,7 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
void MapRequestTracker::Tick(Serial finishedSerial) {
|
||||
for (auto& request : mInflightRequests.IterateUpTo(finishedSerial)) {
|
||||
request.buffer->OnMapCommandSerialFinished(request.mapSerial, request.offset,
|
||||
request.isWrite);
|
||||
request.buffer->OnMapCommandSerialFinished(request.mapSerial, request.isWrite);
|
||||
}
|
||||
mInflightRequests.ClearUpTo(finishedSerial);
|
||||
}
|
||||
|
|
|
@ -193,9 +193,9 @@ namespace dawn_native { namespace null {
|
|||
|
||||
void Buffer::MapReadOperationCompleted(uint32_t serial, void* ptr, bool isWrite) {
|
||||
if (isWrite) {
|
||||
CallMapWriteCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, ptr);
|
||||
CallMapWriteCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, ptr, GetSize());
|
||||
} else {
|
||||
CallMapReadCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, ptr);
|
||||
CallMapReadCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, ptr, GetSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,21 +206,20 @@ namespace dawn_native { namespace null {
|
|||
return {};
|
||||
}
|
||||
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
|
||||
MapAsyncImplCommon(serial, start, count, false);
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial) {
|
||||
MapAsyncImplCommon(serial, false);
|
||||
}
|
||||
|
||||
void Buffer::MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
|
||||
MapAsyncImplCommon(serial, start, count, true);
|
||||
void Buffer::MapWriteAsyncImpl(uint32_t serial) {
|
||||
MapAsyncImplCommon(serial, true);
|
||||
}
|
||||
|
||||
void Buffer::MapAsyncImplCommon(uint32_t serial, uint32_t start, uint32_t count, bool isWrite) {
|
||||
ASSERT(start + count <= GetSize());
|
||||
void Buffer::MapAsyncImplCommon(uint32_t serial, bool isWrite) {
|
||||
ASSERT(mBackingData);
|
||||
|
||||
auto operation = new BufferMapReadOperation;
|
||||
operation->buffer = this;
|
||||
operation->ptr = mBackingData.get() + start;
|
||||
operation->ptr = mBackingData.get();
|
||||
operation->serial = serial;
|
||||
operation->isWrite = isWrite;
|
||||
|
||||
|
|
|
@ -147,11 +147,11 @@ namespace dawn_native { namespace null {
|
|||
|
||||
private:
|
||||
MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const uint8_t* data) override;
|
||||
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
|
||||
void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
|
||||
void MapReadAsyncImpl(uint32_t serial) override;
|
||||
void MapWriteAsyncImpl(uint32_t serial) override;
|
||||
void UnmapImpl() override;
|
||||
|
||||
void MapAsyncImplCommon(uint32_t serial, uint32_t start, uint32_t count, bool isWrite);
|
||||
void MapAsyncImplCommon(uint32_t serial, bool isWrite);
|
||||
|
||||
std::unique_ptr<char[]> mBackingData;
|
||||
};
|
||||
|
|
|
@ -37,20 +37,20 @@ namespace dawn_native { namespace opengl {
|
|||
return {};
|
||||
}
|
||||
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial) {
|
||||
// TODO(cwallez@chromium.org): this does GPU->CPU synchronization, we could require a high
|
||||
// version of OpenGL that would let us map the buffer unsynchronized.
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
||||
void* data = glMapBufferRange(GL_ARRAY_BUFFER, start, count, GL_MAP_READ_BIT);
|
||||
CallMapReadCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data);
|
||||
void* data = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
|
||||
CallMapReadCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data, GetSize());
|
||||
}
|
||||
|
||||
void Buffer::MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
|
||||
void Buffer::MapWriteAsyncImpl(uint32_t serial) {
|
||||
// TODO(cwallez@chromium.org): this does GPU->CPU synchronization, we could require a high
|
||||
// version of OpenGL that would let us map the buffer unsynchronized.
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
|
||||
void* data = glMapBufferRange(GL_ARRAY_BUFFER, start, count, GL_MAP_WRITE_BIT);
|
||||
CallMapWriteCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data);
|
||||
void* data = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
CallMapWriteCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data, GetSize());
|
||||
}
|
||||
|
||||
void Buffer::UnmapImpl() {
|
||||
|
|
|
@ -31,8 +31,8 @@ namespace dawn_native { namespace opengl {
|
|||
|
||||
private:
|
||||
MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const uint8_t* data) override;
|
||||
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
|
||||
void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
|
||||
void MapReadAsyncImpl(uint32_t serial) override;
|
||||
void MapWriteAsyncImpl(uint32_t serial) override;
|
||||
void UnmapImpl() override;
|
||||
|
||||
GLuint mBuffer = 0;
|
||||
|
|
|
@ -149,11 +149,11 @@ namespace dawn_native { namespace vulkan {
|
|||
}
|
||||
|
||||
void Buffer::OnMapReadCommandSerialFinished(uint32_t mapSerial, const void* data) {
|
||||
CallMapReadCallback(mapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data);
|
||||
CallMapReadCallback(mapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data, GetSize());
|
||||
}
|
||||
|
||||
void Buffer::OnMapWriteCommandSerialFinished(uint32_t mapSerial, void* data) {
|
||||
CallMapWriteCallback(mapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data);
|
||||
CallMapWriteCallback(mapSerial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data, GetSize());
|
||||
}
|
||||
|
||||
VkBuffer Buffer::GetHandle() const {
|
||||
|
@ -214,7 +214,7 @@ namespace dawn_native { namespace vulkan {
|
|||
return {};
|
||||
}
|
||||
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t /*count*/) {
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial) {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
|
||||
VkCommandBuffer commands = device->GetPendingCommandBuffer();
|
||||
|
@ -224,10 +224,10 @@ namespace dawn_native { namespace vulkan {
|
|||
ASSERT(memory != nullptr);
|
||||
|
||||
MapRequestTracker* tracker = device->GetMapRequestTracker();
|
||||
tracker->Track(this, serial, memory + start, false);
|
||||
tracker->Track(this, serial, memory, false);
|
||||
}
|
||||
|
||||
void Buffer::MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t /*count*/) {
|
||||
void Buffer::MapWriteAsyncImpl(uint32_t serial) {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
|
||||
VkCommandBuffer commands = device->GetPendingCommandBuffer();
|
||||
|
@ -237,7 +237,7 @@ namespace dawn_native { namespace vulkan {
|
|||
ASSERT(memory != nullptr);
|
||||
|
||||
MapRequestTracker* tracker = device->GetMapRequestTracker();
|
||||
tracker->Track(this, serial, memory + start, true);
|
||||
tracker->Track(this, serial, memory, true);
|
||||
}
|
||||
|
||||
void Buffer::UnmapImpl() {
|
||||
|
|
|
@ -42,8 +42,8 @@ namespace dawn_native { namespace vulkan {
|
|||
|
||||
private:
|
||||
MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const uint8_t* data) override;
|
||||
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
|
||||
void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
|
||||
void MapReadAsyncImpl(uint32_t serial) override;
|
||||
void MapWriteAsyncImpl(uint32_t serial) override;
|
||||
void UnmapImpl() override;
|
||||
|
||||
// TODO(b-brber): Remove once alignment constraint is added to validation (dawn:73).
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
namespace dawn_wire { namespace client {
|
||||
|
||||
void ClientBufferMapReadAsync(dawnBuffer cBuffer,
|
||||
uint32_t start,
|
||||
uint32_t size,
|
||||
dawnBufferMapReadCallback callback,
|
||||
dawnCallbackUserdata userdata) {
|
||||
Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer);
|
||||
|
@ -31,15 +29,12 @@ namespace dawn_wire { namespace client {
|
|||
Buffer::MapRequestData request;
|
||||
request.readCallback = callback;
|
||||
request.userdata = userdata;
|
||||
request.size = size;
|
||||
request.isWrite = false;
|
||||
buffer->requests[serial] = request;
|
||||
|
||||
BufferMapAsyncCmd cmd;
|
||||
cmd.bufferId = buffer->id;
|
||||
cmd.requestSerial = serial;
|
||||
cmd.start = start;
|
||||
cmd.size = size;
|
||||
cmd.isWrite = false;
|
||||
|
||||
size_t requiredSize = cmd.GetRequiredSize();
|
||||
|
@ -49,8 +44,6 @@ namespace dawn_wire { namespace client {
|
|||
}
|
||||
|
||||
void ClientBufferMapWriteAsync(dawnBuffer cBuffer,
|
||||
uint32_t start,
|
||||
uint32_t size,
|
||||
dawnBufferMapWriteCallback callback,
|
||||
dawnCallbackUserdata userdata) {
|
||||
Buffer* buffer = reinterpret_cast<Buffer*>(cBuffer);
|
||||
|
@ -61,15 +54,12 @@ namespace dawn_wire { namespace client {
|
|||
Buffer::MapRequestData request;
|
||||
request.writeCallback = callback;
|
||||
request.userdata = userdata;
|
||||
request.size = size;
|
||||
request.isWrite = true;
|
||||
buffer->requests[serial] = request;
|
||||
|
||||
BufferMapAsyncCmd cmd;
|
||||
cmd.bufferId = buffer->id;
|
||||
cmd.requestSerial = serial;
|
||||
cmd.start = start;
|
||||
cmd.size = size;
|
||||
cmd.isWrite = true;
|
||||
|
||||
size_t requiredSize = cmd.GetRequiredSize();
|
||||
|
|
|
@ -29,9 +29,9 @@ namespace dawn_wire { namespace client {
|
|||
void Buffer::ClearMapRequests(dawnBufferMapAsyncStatus status) {
|
||||
for (auto& it : requests) {
|
||||
if (it.second.isWrite) {
|
||||
it.second.writeCallback(status, nullptr, it.second.userdata);
|
||||
it.second.writeCallback(status, nullptr, 0, it.second.userdata);
|
||||
} else {
|
||||
it.second.readCallback(status, nullptr, it.second.userdata);
|
||||
it.second.readCallback(status, nullptr, 0, it.second.userdata);
|
||||
}
|
||||
}
|
||||
requests.clear();
|
||||
|
|
|
@ -36,7 +36,6 @@ namespace dawn_wire { namespace client {
|
|||
dawnBufferMapReadCallback readCallback = nullptr;
|
||||
dawnBufferMapWriteCallback writeCallback = nullptr;
|
||||
dawnCallbackUserdata userdata = 0;
|
||||
uint32_t size = 0;
|
||||
bool isWrite = false;
|
||||
};
|
||||
std::map<uint32_t, MapRequestData> requests;
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace dawn_wire { namespace client {
|
|||
bool Client::DoBufferMapReadAsyncCallback(Buffer* buffer,
|
||||
uint32_t requestSerial,
|
||||
uint32_t status,
|
||||
uint32_t count,
|
||||
uint32_t dataLength,
|
||||
const uint8_t* data) {
|
||||
// The buffer might have been deleted or recreated so this isn't an error.
|
||||
if (buffer == nullptr) {
|
||||
|
@ -53,12 +53,6 @@ namespace dawn_wire { namespace client {
|
|||
// On success, we copy the data locally because the IPC buffer isn't valid outside of this
|
||||
// function
|
||||
if (status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS) {
|
||||
// The server didn't send the right amount of data, this is an error and could cause
|
||||
// the application to crash if we did call the callback.
|
||||
if (request.size != count) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ASSERT(data != nullptr);
|
||||
|
||||
if (buffer->mappedData != nullptr) {
|
||||
|
@ -66,14 +60,14 @@ namespace dawn_wire { namespace client {
|
|||
}
|
||||
|
||||
buffer->isWriteMapped = false;
|
||||
buffer->mappedDataSize = request.size;
|
||||
buffer->mappedData = malloc(request.size);
|
||||
memcpy(buffer->mappedData, data, request.size);
|
||||
buffer->mappedDataSize = dataLength;
|
||||
buffer->mappedData = malloc(dataLength);
|
||||
memcpy(buffer->mappedData, data, dataLength);
|
||||
|
||||
request.readCallback(static_cast<dawnBufferMapAsyncStatus>(status), buffer->mappedData,
|
||||
request.userdata);
|
||||
dataLength, request.userdata);
|
||||
} else {
|
||||
request.readCallback(static_cast<dawnBufferMapAsyncStatus>(status), nullptr,
|
||||
request.readCallback(static_cast<dawnBufferMapAsyncStatus>(status), nullptr, 0,
|
||||
request.userdata);
|
||||
}
|
||||
|
||||
|
@ -82,7 +76,8 @@ namespace dawn_wire { namespace client {
|
|||
|
||||
bool Client::DoBufferMapWriteAsyncCallback(Buffer* buffer,
|
||||
uint32_t requestSerial,
|
||||
uint32_t status) {
|
||||
uint32_t status,
|
||||
uint32_t dataLength) {
|
||||
// The buffer might have been deleted or recreated so this isn't an error.
|
||||
if (buffer == nullptr) {
|
||||
return true;
|
||||
|
@ -112,14 +107,14 @@ namespace dawn_wire { namespace client {
|
|||
}
|
||||
|
||||
buffer->isWriteMapped = true;
|
||||
buffer->mappedDataSize = request.size;
|
||||
buffer->mappedData = malloc(request.size);
|
||||
memset(buffer->mappedData, 0, request.size);
|
||||
buffer->mappedDataSize = dataLength;
|
||||
buffer->mappedData = malloc(dataLength);
|
||||
memset(buffer->mappedData, 0, dataLength);
|
||||
|
||||
request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(status), buffer->mappedData,
|
||||
request.userdata);
|
||||
dataLength, request.userdata);
|
||||
} else {
|
||||
request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(status), nullptr,
|
||||
request.writeCallback(static_cast<dawnBufferMapAsyncStatus>(status), nullptr, 0,
|
||||
request.userdata);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,9 +49,11 @@ namespace dawn_wire { namespace server {
|
|||
static void ForwardDeviceError(const char* message, dawnCallbackUserdata userdata);
|
||||
static void ForwardBufferMapReadAsync(dawnBufferMapAsyncStatus status,
|
||||
const void* ptr,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata);
|
||||
static void ForwardBufferMapWriteAsync(dawnBufferMapAsyncStatus status,
|
||||
void* ptr,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata);
|
||||
static void ForwardFenceCompletedValue(dawnFenceCompletionStatus status,
|
||||
dawnCallbackUserdata userdata);
|
||||
|
@ -60,9 +62,11 @@ namespace dawn_wire { namespace server {
|
|||
void OnDeviceError(const char* message);
|
||||
void OnBufferMapReadAsyncCallback(dawnBufferMapAsyncStatus status,
|
||||
const void* ptr,
|
||||
uint32_t dataLength,
|
||||
MapUserdata* userdata);
|
||||
void OnBufferMapWriteAsyncCallback(dawnBufferMapAsyncStatus status,
|
||||
void* ptr,
|
||||
uint32_t dataLength,
|
||||
MapUserdata* userdata);
|
||||
void OnFenceCompletedValueUpdated(FenceCompletionUserdata* userdata);
|
||||
|
||||
|
|
|
@ -30,8 +30,6 @@ namespace dawn_wire { namespace server {
|
|||
|
||||
bool Server::DoBufferMapAsync(ObjectId bufferId,
|
||||
uint32_t requestSerial,
|
||||
uint32_t start,
|
||||
uint32_t size,
|
||||
bool isWrite) {
|
||||
// These requests are just forwarded to the buffer, with userdata containing what the
|
||||
// client will require in the return command.
|
||||
|
@ -50,7 +48,6 @@ namespace dawn_wire { namespace server {
|
|||
data->server = this;
|
||||
data->buffer = ObjectHandle{bufferId, buffer->serial};
|
||||
data->requestSerial = requestSerial;
|
||||
data->size = size;
|
||||
data->isWrite = isWrite;
|
||||
|
||||
auto userdata = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(data));
|
||||
|
@ -58,19 +55,18 @@ namespace dawn_wire { namespace server {
|
|||
if (!buffer->valid) {
|
||||
// Fake the buffer returning a failure, data will be freed in this call.
|
||||
if (isWrite) {
|
||||
ForwardBufferMapWriteAsync(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata);
|
||||
ForwardBufferMapWriteAsync(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0,
|
||||
userdata);
|
||||
} else {
|
||||
ForwardBufferMapReadAsync(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata);
|
||||
ForwardBufferMapReadAsync(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isWrite) {
|
||||
mProcs.bufferMapWriteAsync(buffer->handle, start, size, ForwardBufferMapWriteAsync,
|
||||
userdata);
|
||||
mProcs.bufferMapWriteAsync(buffer->handle, ForwardBufferMapWriteAsync, userdata);
|
||||
} else {
|
||||
mProcs.bufferMapReadAsync(buffer->handle, start, size, ForwardBufferMapReadAsync,
|
||||
userdata);
|
||||
mProcs.bufferMapReadAsync(buffer->handle, ForwardBufferMapReadAsync, userdata);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -99,20 +95,23 @@ namespace dawn_wire { namespace server {
|
|||
|
||||
void Server::ForwardBufferMapReadAsync(dawnBufferMapAsyncStatus status,
|
||||
const void* ptr,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata) {
|
||||
auto data = reinterpret_cast<MapUserdata*>(static_cast<uintptr_t>(userdata));
|
||||
data->server->OnBufferMapReadAsyncCallback(status, ptr, data);
|
||||
data->server->OnBufferMapReadAsyncCallback(status, ptr, dataLength, data);
|
||||
}
|
||||
|
||||
void Server::ForwardBufferMapWriteAsync(dawnBufferMapAsyncStatus status,
|
||||
void* ptr,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata) {
|
||||
auto data = reinterpret_cast<MapUserdata*>(static_cast<uintptr_t>(userdata));
|
||||
data->server->OnBufferMapWriteAsyncCallback(status, ptr, data);
|
||||
data->server->OnBufferMapWriteAsyncCallback(status, ptr, dataLength, data);
|
||||
}
|
||||
|
||||
void Server::OnBufferMapReadAsyncCallback(dawnBufferMapAsyncStatus status,
|
||||
const void* ptr,
|
||||
uint32_t dataLength,
|
||||
MapUserdata* userdata) {
|
||||
std::unique_ptr<MapUserdata> data(userdata);
|
||||
|
||||
|
@ -130,7 +129,7 @@ namespace dawn_wire { namespace server {
|
|||
cmd.data = reinterpret_cast<const uint8_t*>(ptr);
|
||||
|
||||
if (status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS) {
|
||||
cmd.dataLength = data->size;
|
||||
cmd.dataLength = dataLength;
|
||||
}
|
||||
|
||||
size_t requiredSize = cmd.GetRequiredSize();
|
||||
|
@ -140,6 +139,7 @@ namespace dawn_wire { namespace server {
|
|||
|
||||
void Server::OnBufferMapWriteAsyncCallback(dawnBufferMapAsyncStatus status,
|
||||
void* ptr,
|
||||
uint32_t dataLength,
|
||||
MapUserdata* userdata) {
|
||||
std::unique_ptr<MapUserdata> data(userdata);
|
||||
|
||||
|
@ -153,6 +153,7 @@ namespace dawn_wire { namespace server {
|
|||
cmd.buffer = data->buffer;
|
||||
cmd.requestSerial = data->requestSerial;
|
||||
cmd.status = status;
|
||||
cmd.dataLength = dataLength;
|
||||
|
||||
size_t requiredSize = cmd.GetRequiredSize();
|
||||
char* allocatedBuffer = static_cast<char*>(GetCmdSpace(requiredSize));
|
||||
|
@ -160,7 +161,7 @@ namespace dawn_wire { namespace server {
|
|||
|
||||
if (status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS) {
|
||||
bufferData->mappedData = ptr;
|
||||
bufferData->mappedDataSize = data->size;
|
||||
bufferData->mappedDataSize = dataLength;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -386,9 +386,8 @@ void DawnTest::MapSlotsSynchronously() {
|
|||
auto userdata = new MapReadUserdata{this, i};
|
||||
|
||||
auto& slot = mReadbackSlots[i];
|
||||
slot.buffer.MapReadAsync(
|
||||
0, slot.bufferSize, SlotMapReadCallback,
|
||||
static_cast<dawn::CallbackUserdata>(reinterpret_cast<uintptr_t>(userdata)));
|
||||
slot.buffer.MapReadAsync(SlotMapReadCallback, static_cast<dawn::CallbackUserdata>(
|
||||
reinterpret_cast<uintptr_t>(userdata)));
|
||||
}
|
||||
|
||||
// Busy wait until all map operations are done.
|
||||
|
@ -400,6 +399,7 @@ void DawnTest::MapSlotsSynchronously() {
|
|||
// static
|
||||
void DawnTest::SlotMapReadCallback(dawnBufferMapAsyncStatus status,
|
||||
const void* data,
|
||||
uint32_t,
|
||||
dawnCallbackUserdata userdata_) {
|
||||
DAWN_ASSERT(status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS);
|
||||
|
||||
|
|
|
@ -148,6 +148,7 @@ class DawnTest : public ::testing::TestWithParam<dawn_native::BackendType> {
|
|||
void MapSlotsSynchronously();
|
||||
static void SlotMapReadCallback(dawnBufferMapAsyncStatus status,
|
||||
const void* data,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata);
|
||||
size_t mNumPendingMapOperations = 0;
|
||||
|
||||
|
|
|
@ -18,29 +18,33 @@
|
|||
|
||||
class BufferMapReadTests : public DawnTest {
|
||||
protected:
|
||||
static void MapReadCallback(dawnBufferMapAsyncStatus status, const void* data, dawnCallbackUserdata userdata) {
|
||||
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status);
|
||||
ASSERT_NE(nullptr, data);
|
||||
static void MapReadCallback(dawnBufferMapAsyncStatus status,
|
||||
const void* data,
|
||||
uint32_t,
|
||||
dawnCallbackUserdata userdata) {
|
||||
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status);
|
||||
ASSERT_NE(nullptr, data);
|
||||
|
||||
auto test = reinterpret_cast<BufferMapReadTests*>(static_cast<uintptr_t>(userdata));
|
||||
test->mappedData = data;
|
||||
}
|
||||
auto test = reinterpret_cast<BufferMapReadTests*>(static_cast<uintptr_t>(userdata));
|
||||
test->mappedData = data;
|
||||
}
|
||||
|
||||
const void* MapReadAsyncAndWait(const dawn::Buffer& buffer, uint32_t start, uint32_t offset) {
|
||||
buffer.MapReadAsync(start, offset, MapReadCallback, static_cast<dawn::CallbackUserdata>(reinterpret_cast<uintptr_t>(this)));
|
||||
const void* MapReadAsyncAndWait(const dawn::Buffer& buffer) {
|
||||
buffer.MapReadAsync(MapReadCallback, static_cast<dawn::CallbackUserdata>(
|
||||
reinterpret_cast<uintptr_t>(this)));
|
||||
|
||||
while (mappedData == nullptr) {
|
||||
WaitABit();
|
||||
}
|
||||
while (mappedData == nullptr) {
|
||||
WaitABit();
|
||||
}
|
||||
|
||||
return mappedData;
|
||||
}
|
||||
return mappedData;
|
||||
}
|
||||
|
||||
private:
|
||||
const void* mappedData = nullptr;
|
||||
};
|
||||
|
||||
// Test that the simplest map read (one u8 at offset 0) works.
|
||||
// Test that the simplest map read works.
|
||||
TEST_P(BufferMapReadTests, SmallReadAtZero) {
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 1;
|
||||
|
@ -50,45 +54,13 @@ TEST_P(BufferMapReadTests, SmallReadAtZero) {
|
|||
uint8_t myData = 187;
|
||||
buffer.SetSubData(0, sizeof(myData), &myData);
|
||||
|
||||
const void* mappedData = MapReadAsyncAndWait(buffer, 0, 1);
|
||||
const void* mappedData = MapReadAsyncAndWait(buffer);
|
||||
ASSERT_EQ(myData, *reinterpret_cast<const uint8_t*>(mappedData));
|
||||
|
||||
buffer.Unmap();
|
||||
}
|
||||
|
||||
// Test mapping a buffer at an offset.
|
||||
TEST_P(BufferMapReadTests, SmallReadAtOffset) {
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4000;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
uint8_t myData = 234;
|
||||
buffer.SetSubData(2048, sizeof(myData), &myData);
|
||||
|
||||
const void* mappedData = MapReadAsyncAndWait(buffer, 2048, 4);
|
||||
ASSERT_EQ(myData, *reinterpret_cast<const uint8_t*>(mappedData));
|
||||
|
||||
buffer.Unmap();
|
||||
}
|
||||
|
||||
// Test mapping a buffer at an offset that's not uint32-aligned.
|
||||
TEST_P(BufferMapReadTests, SmallReadAtUnalignedOffset) {
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4000;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
uint8_t myData = 213;
|
||||
buffer.SetSubData(3, 1, &myData);
|
||||
|
||||
const void* mappedData = MapReadAsyncAndWait(buffer, 3, 1);
|
||||
ASSERT_EQ(myData, *reinterpret_cast<const uint8_t*>(mappedData));
|
||||
|
||||
buffer.Unmap();
|
||||
}
|
||||
|
||||
// Test mapping large ranges of a buffer.
|
||||
// Test mapping a large buffer.
|
||||
TEST_P(BufferMapReadTests, LargeRead) {
|
||||
constexpr uint32_t kDataSize = 1000 * 1000;
|
||||
std::vector<uint32_t> myData;
|
||||
|
@ -103,7 +75,7 @@ TEST_P(BufferMapReadTests, LargeRead) {
|
|||
|
||||
buffer.SetSubData(0, kDataSize * sizeof(uint32_t), reinterpret_cast<uint8_t*>(myData.data()));
|
||||
|
||||
const void* mappedData = MapReadAsyncAndWait(buffer, 0, static_cast<uint32_t>(kDataSize * sizeof(uint32_t)));
|
||||
const void* mappedData = MapReadAsyncAndWait(buffer);
|
||||
ASSERT_EQ(0, memcmp(mappedData, myData.data(), kDataSize * sizeof(uint32_t)));
|
||||
|
||||
buffer.Unmap();
|
||||
|
@ -113,30 +85,33 @@ DAWN_INSTANTIATE_TEST(BufferMapReadTests, D3D12Backend, MetalBackend, OpenGLBack
|
|||
|
||||
class BufferMapWriteTests : public DawnTest {
|
||||
protected:
|
||||
static void MapWriteCallback(dawnBufferMapAsyncStatus status,
|
||||
void* data,
|
||||
uint32_t,
|
||||
dawnCallbackUserdata userdata) {
|
||||
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status);
|
||||
ASSERT_NE(nullptr, data);
|
||||
|
||||
static void MapWriteCallback(dawnBufferMapAsyncStatus status, void* data, dawnCallbackUserdata userdata) {
|
||||
ASSERT_EQ(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, status);
|
||||
ASSERT_NE(nullptr, data);
|
||||
auto test = reinterpret_cast<BufferMapWriteTests*>(static_cast<uintptr_t>(userdata));
|
||||
test->mappedData = data;
|
||||
}
|
||||
|
||||
auto test = reinterpret_cast<BufferMapWriteTests*>(static_cast<uintptr_t>(userdata));
|
||||
test->mappedData = data;
|
||||
}
|
||||
void* MapWriteAsyncAndWait(const dawn::Buffer& buffer) {
|
||||
buffer.MapWriteAsync(MapWriteCallback, static_cast<dawn::CallbackUserdata>(
|
||||
reinterpret_cast<uintptr_t>(this)));
|
||||
|
||||
void* MapWriteAsyncAndWait(const dawn::Buffer& buffer, uint32_t start, uint32_t offset) {
|
||||
buffer.MapWriteAsync(start, offset, MapWriteCallback, static_cast<dawn::CallbackUserdata>(reinterpret_cast<uintptr_t>(this)));
|
||||
while (mappedData == nullptr) {
|
||||
WaitABit();
|
||||
}
|
||||
|
||||
while (mappedData == nullptr) {
|
||||
WaitABit();
|
||||
}
|
||||
|
||||
return mappedData;
|
||||
}
|
||||
return mappedData;
|
||||
}
|
||||
|
||||
private:
|
||||
void* mappedData = nullptr;
|
||||
};
|
||||
|
||||
// Test that the simplest map write (one u32 at offset 0) works.
|
||||
// Test that the simplest map write works.
|
||||
TEST_P(BufferMapWriteTests, SmallWriteAtZero) {
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4;
|
||||
|
@ -144,29 +119,14 @@ TEST_P(BufferMapWriteTests, SmallWriteAtZero) {
|
|||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
uint32_t myData = 2934875;
|
||||
void* mappedData = MapWriteAsyncAndWait(buffer, 0, 4);
|
||||
void* mappedData = MapWriteAsyncAndWait(buffer);
|
||||
memcpy(mappedData, &myData, sizeof(myData));
|
||||
buffer.Unmap();
|
||||
|
||||
EXPECT_BUFFER_U32_EQ(myData, buffer, 0);
|
||||
}
|
||||
|
||||
// Test mapping a buffer at an offset.
|
||||
TEST_P(BufferMapWriteTests, SmallWriteAtOffset) {
|
||||
dawn::BufferDescriptor descriptor;
|
||||
descriptor.size = 4000;
|
||||
descriptor.usage = dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
uint32_t myData = 2934875;
|
||||
void* mappedData = MapWriteAsyncAndWait(buffer, 2048, 4);
|
||||
memcpy(mappedData, &myData, sizeof(myData));
|
||||
buffer.Unmap();
|
||||
|
||||
EXPECT_BUFFER_U32_EQ(myData, buffer, 2048);
|
||||
}
|
||||
|
||||
// Test mapping large ranges of a buffer.
|
||||
// Test mapping a large buffer.
|
||||
TEST_P(BufferMapWriteTests, LargeWrite) {
|
||||
constexpr uint32_t kDataSize = 1000 * 1000;
|
||||
std::vector<uint32_t> myData;
|
||||
|
@ -179,7 +139,7 @@ TEST_P(BufferMapWriteTests, LargeWrite) {
|
|||
descriptor.usage = dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc;
|
||||
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
|
||||
|
||||
void* mappedData = MapWriteAsyncAndWait(buffer, 0, kDataSize * sizeof(uint32_t));
|
||||
void* mappedData = MapWriteAsyncAndWait(buffer);
|
||||
memcpy(mappedData, myData.data(), kDataSize * sizeof(uint32_t));
|
||||
buffer.Unmap();
|
||||
|
||||
|
|
|
@ -22,24 +22,40 @@ using namespace testing;
|
|||
|
||||
class MockBufferMapReadCallback {
|
||||
public:
|
||||
MOCK_METHOD3(Call, void(dawnBufferMapAsyncStatus status, const uint32_t* ptr, dawnCallbackUserdata userdata));
|
||||
MOCK_METHOD4(Call,
|
||||
void(dawnBufferMapAsyncStatus status,
|
||||
const uint32_t* ptr,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata));
|
||||
};
|
||||
|
||||
static std::unique_ptr<MockBufferMapReadCallback> mockBufferMapReadCallback;
|
||||
static void ToMockBufferMapReadCallback(dawnBufferMapAsyncStatus status, const void* ptr, dawnCallbackUserdata userdata) {
|
||||
static void ToMockBufferMapReadCallback(dawnBufferMapAsyncStatus status,
|
||||
const void* ptr,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata) {
|
||||
// Assume the data is uint32_t to make writing matchers easier
|
||||
mockBufferMapReadCallback->Call(status, reinterpret_cast<const uint32_t*>(ptr), userdata);
|
||||
mockBufferMapReadCallback->Call(status, reinterpret_cast<const uint32_t*>(ptr), dataLength,
|
||||
userdata);
|
||||
}
|
||||
|
||||
class MockBufferMapWriteCallback {
|
||||
public:
|
||||
MOCK_METHOD3(Call, void(dawnBufferMapAsyncStatus status, uint32_t* ptr, dawnCallbackUserdata userdata));
|
||||
MOCK_METHOD4(Call,
|
||||
void(dawnBufferMapAsyncStatus status,
|
||||
uint32_t* ptr,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata));
|
||||
};
|
||||
|
||||
static std::unique_ptr<MockBufferMapWriteCallback> mockBufferMapWriteCallback;
|
||||
static void ToMockBufferMapWriteCallback(dawnBufferMapAsyncStatus status, void* ptr, dawnCallbackUserdata userdata) {
|
||||
static void ToMockBufferMapWriteCallback(dawnBufferMapAsyncStatus status,
|
||||
void* ptr,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata) {
|
||||
// Assume the data is uint32_t to make writing matchers easier
|
||||
mockBufferMapWriteCallback->Call(status, reinterpret_cast<uint32_t*>(ptr), userdata);
|
||||
mockBufferMapWriteCallback->Call(status, reinterpret_cast<uint32_t*>(ptr), dataLength,
|
||||
userdata);
|
||||
}
|
||||
|
||||
class BufferValidationTest : public ValidationTest {
|
||||
|
@ -142,9 +158,10 @@ TEST_F(BufferValidationTest, MapReadSuccess) {
|
|||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40598;
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata))
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata))
|
||||
.Times(1);
|
||||
queue.Submit(0, nullptr);
|
||||
|
||||
|
@ -156,67 +173,16 @@ TEST_F(BufferValidationTest, MapWriteSuccess) {
|
|||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40598;
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, userdata);
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata))
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata))
|
||||
.Times(1);
|
||||
queue.Submit(0, nullptr);
|
||||
|
||||
buf.Unmap();
|
||||
}
|
||||
|
||||
// Test map reading out of range causes an error
|
||||
TEST_F(BufferValidationTest, MapReadOutOfRange) {
|
||||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40599;
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
.Times(1);
|
||||
|
||||
ASSERT_DEVICE_ERROR(buf.MapReadAsync(0, 5, ToMockBufferMapReadCallback, userdata));
|
||||
}
|
||||
|
||||
// Test map writing out of range causes an error
|
||||
TEST_F(BufferValidationTest, MapWriteOutOfRange) {
|
||||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40599;
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
.Times(1);
|
||||
|
||||
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(0, 5, ToMockBufferMapWriteCallback, userdata));
|
||||
}
|
||||
|
||||
// Test map reading out of range causes an error, with an overflow
|
||||
TEST_F(BufferValidationTest, MapReadOutOfRangeOverflow) {
|
||||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40599;
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
.Times(1);
|
||||
|
||||
// An offset that when added to "2" would overflow to be zero and pass validation without
|
||||
// overflow checks.
|
||||
uint32_t offset = uint32_t(int32_t(0) - int32_t(2));
|
||||
|
||||
ASSERT_DEVICE_ERROR(buf.MapReadAsync(offset, 2, ToMockBufferMapReadCallback, userdata));
|
||||
}
|
||||
|
||||
// Test map writing out of range causes an error, with an overflow
|
||||
TEST_F(BufferValidationTest, MapWriteOutOfRangeOverflow) {
|
||||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40599;
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
.Times(1);
|
||||
|
||||
// An offset that when added to "2" would overflow to be zero and pass validation without
|
||||
// overflow checks.
|
||||
uint32_t offset = uint32_t(int32_t(0) - int32_t(2));
|
||||
|
||||
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(offset, 5, ToMockBufferMapWriteCallback, userdata));
|
||||
}
|
||||
|
||||
// Test map reading a buffer with wrong current usage
|
||||
TEST_F(BufferValidationTest, MapReadWrongUsage) {
|
||||
dawn::BufferDescriptor descriptor;
|
||||
|
@ -226,10 +192,11 @@ TEST_F(BufferValidationTest, MapReadWrongUsage) {
|
|||
dawn::Buffer buf = device.CreateBuffer(&descriptor);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40600;
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0u, userdata))
|
||||
.Times(1);
|
||||
|
||||
ASSERT_DEVICE_ERROR(buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata));
|
||||
ASSERT_DEVICE_ERROR(buf.MapReadAsync(ToMockBufferMapReadCallback, userdata));
|
||||
}
|
||||
|
||||
// Test map writing a buffer with wrong current usage
|
||||
|
@ -241,10 +208,11 @@ TEST_F(BufferValidationTest, MapWriteWrongUsage) {
|
|||
dawn::Buffer buf = device.CreateBuffer(&descriptor);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40600;
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0u, userdata))
|
||||
.Times(1);
|
||||
|
||||
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, userdata));
|
||||
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata));
|
||||
}
|
||||
|
||||
// Test map reading a buffer that is already mapped
|
||||
|
@ -252,14 +220,16 @@ TEST_F(BufferValidationTest, MapReadAlreadyMapped) {
|
|||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata1 = 40601;
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata1);
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata1))
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata1);
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata1))
|
||||
.Times(1);
|
||||
|
||||
dawn::CallbackUserdata userdata2 = 40602;
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata2))
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0u, userdata2))
|
||||
.Times(1);
|
||||
ASSERT_DEVICE_ERROR(buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata2));
|
||||
ASSERT_DEVICE_ERROR(buf.MapReadAsync(ToMockBufferMapReadCallback, userdata2));
|
||||
|
||||
queue.Submit(0, nullptr);
|
||||
}
|
||||
|
@ -269,14 +239,16 @@ TEST_F(BufferValidationTest, MapWriteAlreadyMapped) {
|
|||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata1 = 40601;
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, userdata1);
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata1))
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata1);
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata1))
|
||||
.Times(1);
|
||||
|
||||
dawn::CallbackUserdata userdata2 = 40602;
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata2))
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0u, userdata2))
|
||||
.Times(1);
|
||||
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, userdata2));
|
||||
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata2));
|
||||
|
||||
queue.Submit(0, nullptr);
|
||||
}
|
||||
|
@ -287,9 +259,10 @@ TEST_F(BufferValidationTest, MapReadUnmapBeforeResult) {
|
|||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40603;
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, userdata))
|
||||
.Times(1);
|
||||
buf.Unmap();
|
||||
|
||||
|
@ -303,9 +276,10 @@ TEST_F(BufferValidationTest, MapWriteUnmapBeforeResult) {
|
|||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40603;
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, userdata);
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, userdata))
|
||||
.Times(1);
|
||||
buf.Unmap();
|
||||
|
||||
|
@ -322,9 +296,10 @@ TEST_F(BufferValidationTest, DISABLED_MapReadDestroyBeforeResult) {
|
|||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40604;
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, userdata))
|
||||
.Times(1);
|
||||
}
|
||||
|
||||
|
@ -341,9 +316,10 @@ TEST_F(BufferValidationTest, DISABLED_MapWriteDestroyBeforeResult) {
|
|||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40604;
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, userdata);
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, userdata))
|
||||
.Times(1);
|
||||
}
|
||||
|
||||
|
@ -358,17 +334,19 @@ TEST_F(BufferValidationTest, MapReadUnmapBeforeResultThenMapAgain) {
|
|||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40605;
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, userdata))
|
||||
.Times(1);
|
||||
buf.Unmap();
|
||||
|
||||
userdata ++;
|
||||
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata))
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata))
|
||||
.Times(1);
|
||||
queue.Submit(0, nullptr);
|
||||
}
|
||||
|
@ -380,17 +358,19 @@ TEST_F(BufferValidationTest, MapWriteUnmapBeforeResultThenMapAgain) {
|
|||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40605;
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, userdata);
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0u, userdata))
|
||||
.Times(1);
|
||||
buf.Unmap();
|
||||
|
||||
userdata ++;
|
||||
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, userdata);
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata))
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata))
|
||||
.Times(1);
|
||||
queue.Submit(0, nullptr);
|
||||
}
|
||||
|
@ -400,12 +380,11 @@ TEST_F(BufferValidationTest, UnmapInsideMapReadCallback) {
|
|||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40678;
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
buf.Unmap();
|
||||
}));
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata))
|
||||
.WillOnce(InvokeWithoutArgs([&]() { buf.Unmap(); }));
|
||||
|
||||
queue.Submit(0, nullptr);
|
||||
}
|
||||
|
@ -415,12 +394,11 @@ TEST_F(BufferValidationTest, UnmapInsideMapWriteCallback) {
|
|||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40678;
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, userdata);
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
buf.Unmap();
|
||||
}));
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata))
|
||||
.WillOnce(InvokeWithoutArgs([&]() { buf.Unmap(); }));
|
||||
|
||||
queue.Submit(0, nullptr);
|
||||
}
|
||||
|
@ -430,12 +408,11 @@ TEST_F(BufferValidationTest, DestroyInsideMapReadCallback) {
|
|||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40679;
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
buf = dawn::Buffer();
|
||||
}));
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata))
|
||||
.WillOnce(InvokeWithoutArgs([&]() { buf = dawn::Buffer(); }));
|
||||
|
||||
queue.Submit(0, nullptr);
|
||||
}
|
||||
|
@ -445,12 +422,11 @@ TEST_F(BufferValidationTest, DestroyInsideMapWriteCallback) {
|
|||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
|
||||
dawn::CallbackUserdata userdata = 40679;
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, userdata);
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), userdata))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
buf = dawn::Buffer();
|
||||
}));
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Ne(nullptr), 4u, userdata))
|
||||
.WillOnce(InvokeWithoutArgs([&]() { buf = dawn::Buffer(); }));
|
||||
|
||||
queue.Submit(0, nullptr);
|
||||
}
|
||||
|
@ -512,12 +488,12 @@ TEST_F(BufferValidationTest, DestroyUnmappedBuffer) {
|
|||
TEST_F(BufferValidationTest, DestroyMappedBuffer) {
|
||||
{
|
||||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, 30303);
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, 30303);
|
||||
buf.Destroy();
|
||||
}
|
||||
{
|
||||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, 30233);
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, 30233);
|
||||
buf.Destroy();
|
||||
}
|
||||
}
|
||||
|
@ -527,10 +503,10 @@ TEST_F(BufferValidationTest, DestroyMappedBufferCausesImplicitUnmap) {
|
|||
{
|
||||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
dawn::CallbackUserdata userdata = 40598;
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, userdata);
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, userdata);
|
||||
// Buffer is destroyed. Callback should be called with UNKNOWN status
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, userdata))
|
||||
.Times(1);
|
||||
buf.Destroy();
|
||||
queue.Submit(0, nullptr);
|
||||
|
@ -538,10 +514,10 @@ TEST_F(BufferValidationTest, DestroyMappedBufferCausesImplicitUnmap) {
|
|||
{
|
||||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
dawn::CallbackUserdata userdata = 23980;
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, userdata);
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, userdata);
|
||||
// Buffer is destroyed. Callback should be called with UNKNOWN status
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, userdata))
|
||||
.Times(1);
|
||||
buf.Destroy();
|
||||
queue.Submit(0, nullptr);
|
||||
|
@ -574,12 +550,12 @@ TEST_F(BufferValidationTest, MapDestroyedBuffer) {
|
|||
{
|
||||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
buf.Destroy();
|
||||
ASSERT_DEVICE_ERROR(buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, 11303));
|
||||
ASSERT_DEVICE_ERROR(buf.MapReadAsync(ToMockBufferMapReadCallback, 11303));
|
||||
}
|
||||
{
|
||||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
buf.Destroy();
|
||||
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, 56303));
|
||||
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(ToMockBufferMapWriteCallback, 56303));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -595,14 +571,14 @@ TEST_F(BufferValidationTest, SetSubDataDestroyedBuffer) {
|
|||
TEST_F(BufferValidationTest, MapMappedbuffer) {
|
||||
{
|
||||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, 43309);
|
||||
ASSERT_DEVICE_ERROR(buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, 34309));
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, 43309);
|
||||
ASSERT_DEVICE_ERROR(buf.MapReadAsync(ToMockBufferMapReadCallback, 34309));
|
||||
queue.Submit(0, nullptr);
|
||||
}
|
||||
{
|
||||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, 20301);
|
||||
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, 40303));
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, 20301);
|
||||
ASSERT_DEVICE_ERROR(buf.MapWriteAsync(ToMockBufferMapWriteCallback, 40303));
|
||||
queue.Submit(0, nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -611,14 +587,14 @@ TEST_F(BufferValidationTest, MapMappedbuffer) {
|
|||
TEST_F(BufferValidationTest, SetSubDataMappedBuffer) {
|
||||
{
|
||||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, 42899);
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, 42899);
|
||||
uint8_t foo = 0;
|
||||
ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(foo), &foo));
|
||||
queue.Submit(0, nullptr);
|
||||
}
|
||||
{
|
||||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, 40329);
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, 40329);
|
||||
uint8_t foo = 0;
|
||||
ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(foo), &foo));
|
||||
queue.Submit(0, nullptr);
|
||||
|
@ -657,7 +633,7 @@ TEST_F(BufferValidationTest, SubmitMappedBuffer) {
|
|||
dawn::Buffer bufA = device.CreateBuffer(&descriptorA);
|
||||
dawn::Buffer bufB = device.CreateBuffer(&descriptorB);
|
||||
|
||||
bufA.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, 40329);
|
||||
bufA.MapWriteAsync(ToMockBufferMapWriteCallback, 40329);
|
||||
|
||||
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||
builder.CopyBufferToBuffer(bufA, 0, bufB, 0, 4);
|
||||
|
@ -669,7 +645,7 @@ TEST_F(BufferValidationTest, SubmitMappedBuffer) {
|
|||
dawn::Buffer bufA = device.CreateBuffer(&descriptorA);
|
||||
dawn::Buffer bufB = device.CreateBuffer(&descriptorB);
|
||||
|
||||
bufB.MapReadAsync(0, 4, ToMockBufferMapReadCallback, 11329);
|
||||
bufB.MapReadAsync(ToMockBufferMapReadCallback, 11329);
|
||||
|
||||
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
|
||||
builder.CopyBufferToBuffer(bufA, 0, bufB, 0, 4);
|
||||
|
@ -711,7 +687,7 @@ TEST_F(BufferValidationTest, UnmapUnmappedBuffer) {
|
|||
dawn::Buffer buf = CreateMapReadBuffer(4);
|
||||
// Buffer starts unmapped. Unmap should succeed.
|
||||
buf.Unmap();
|
||||
buf.MapReadAsync(0, 4, ToMockBufferMapReadCallback, 30603);
|
||||
buf.MapReadAsync(ToMockBufferMapReadCallback, 30603);
|
||||
buf.Unmap();
|
||||
// Unmapping twice should succeed
|
||||
buf.Unmap();
|
||||
|
@ -720,7 +696,7 @@ TEST_F(BufferValidationTest, UnmapUnmappedBuffer) {
|
|||
dawn::Buffer buf = CreateMapWriteBuffer(4);
|
||||
// Buffer starts unmapped. Unmap should succeed.
|
||||
buf.Unmap();
|
||||
buf.MapWriteAsync(0, 4, ToMockBufferMapWriteCallback, 23890);
|
||||
buf.MapWriteAsync(ToMockBufferMapWriteCallback, 23890);
|
||||
// Unmapping twice should succeed
|
||||
buf.Unmap();
|
||||
buf.Unmap();
|
||||
|
|
|
@ -21,7 +21,10 @@ namespace {
|
|||
class QueueSubmitValidationTest : public ValidationTest {
|
||||
};
|
||||
|
||||
static void StoreTrueMapWriteCallback(dawnBufferMapAsyncStatus status, void*, dawnCallbackUserdata userdata) {
|
||||
static void StoreTrueMapWriteCallback(dawnBufferMapAsyncStatus status,
|
||||
void*,
|
||||
uint32_t,
|
||||
dawnCallbackUserdata userdata) {
|
||||
bool* userdataPtr = reinterpret_cast<bool*>(static_cast<intptr_t>(userdata));
|
||||
*userdataPtr = true;
|
||||
}
|
||||
|
@ -55,7 +58,7 @@ TEST_F(QueueSubmitValidationTest, SubmitWithMappedBuffer) {
|
|||
// Map the buffer, submitting when the buffer is mapped should fail
|
||||
bool mapWriteFinished = false;
|
||||
dawnCallbackUserdata userdata = static_cast<dawnCallbackUserdata>(reinterpret_cast<intptr_t>(&mapWriteFinished));
|
||||
buffer.MapWriteAsync(0, 4, StoreTrueMapWriteCallback, userdata);
|
||||
buffer.MapWriteAsync(StoreTrueMapWriteCallback, userdata);
|
||||
queue.Submit(0, nullptr);
|
||||
ASSERT_TRUE(mapWriteFinished);
|
||||
|
||||
|
|
|
@ -22,25 +22,29 @@ namespace {
|
|||
// Mock classes to add expectations on the wire calling callbacks
|
||||
class MockBufferMapReadCallback {
|
||||
public:
|
||||
MOCK_METHOD3(Call,
|
||||
MOCK_METHOD4(Call,
|
||||
void(dawnBufferMapAsyncStatus status,
|
||||
const uint32_t* ptr,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata));
|
||||
};
|
||||
|
||||
std::unique_ptr<MockBufferMapReadCallback> mockBufferMapReadCallback;
|
||||
void ToMockBufferMapReadCallback(dawnBufferMapAsyncStatus status,
|
||||
const void* ptr,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata) {
|
||||
// Assume the data is uint32_t to make writing matchers easier
|
||||
mockBufferMapReadCallback->Call(status, static_cast<const uint32_t*>(ptr), userdata);
|
||||
mockBufferMapReadCallback->Call(status, static_cast<const uint32_t*>(ptr), dataLength,
|
||||
userdata);
|
||||
}
|
||||
|
||||
class MockBufferMapWriteCallback {
|
||||
public:
|
||||
MOCK_METHOD3(Call,
|
||||
MOCK_METHOD4(Call,
|
||||
void(dawnBufferMapAsyncStatus status,
|
||||
uint32_t* ptr,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata));
|
||||
};
|
||||
|
||||
|
@ -48,10 +52,11 @@ namespace {
|
|||
uint32_t* lastMapWritePointer = nullptr;
|
||||
void ToMockBufferMapWriteCallback(dawnBufferMapAsyncStatus status,
|
||||
void* ptr,
|
||||
uint32_t dataLength,
|
||||
dawnCallbackUserdata userdata) {
|
||||
// Assume the data is uint32_t to make writing matchers easier
|
||||
lastMapWritePointer = static_cast<uint32_t*>(ptr);
|
||||
mockBufferMapWriteCallback->Call(status, lastMapWritePointer, userdata);
|
||||
mockBufferMapWriteCallback->Call(status, lastMapWritePointer, dataLength, userdata);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
@ -116,19 +121,20 @@ class WireBufferMappingTests : public WireTest {
|
|||
// Check mapping for reading a succesfully created buffer
|
||||
TEST_F(WireBufferMappingTests, MappingForReadSuccessBuffer) {
|
||||
dawnCallbackUserdata userdata = 8653;
|
||||
dawnBufferMapReadAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback, userdata);
|
||||
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
uint32_t bufferContent = 31337;
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
&bufferContent);
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, &bufferContent,
|
||||
sizeof(uint32_t));
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)),
|
||||
sizeof(uint32_t), userdata))
|
||||
.Times(1);
|
||||
|
||||
FlushServer();
|
||||
|
@ -143,17 +149,17 @@ TEST_F(WireBufferMappingTests, MappingForReadSuccessBuffer) {
|
|||
// reading
|
||||
TEST_F(WireBufferMappingTests, ErrorWhileMappingForRead) {
|
||||
dawnCallbackUserdata userdata = 8654;
|
||||
dawnBufferMapReadAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback, userdata);
|
||||
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr);
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0);
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata))
|
||||
.Times(1);
|
||||
|
||||
FlushServer();
|
||||
|
@ -162,13 +168,12 @@ TEST_F(WireBufferMappingTests, ErrorWhileMappingForRead) {
|
|||
// Check mapping for reading a buffer that didn't get created on the server side
|
||||
TEST_F(WireBufferMappingTests, MappingForReadErrorBuffer) {
|
||||
dawnCallbackUserdata userdata = 8655;
|
||||
dawnBufferMapReadAsync(errorBuffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback,
|
||||
userdata);
|
||||
dawnBufferMapReadAsync(errorBuffer, ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata))
|
||||
.Times(1);
|
||||
|
||||
FlushServer();
|
||||
|
@ -182,11 +187,10 @@ TEST_F(WireBufferMappingTests, MappingForReadErrorBuffer) {
|
|||
// request is finished
|
||||
TEST_F(WireBufferMappingTests, DestroyBeforeReadRequestEnd) {
|
||||
dawnCallbackUserdata userdata = 8656;
|
||||
dawnBufferMapReadAsync(errorBuffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback,
|
||||
userdata);
|
||||
dawnBufferMapReadAsync(errorBuffer, ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, userdata))
|
||||
.Times(1);
|
||||
|
||||
dawnBufferRelease(errorBuffer);
|
||||
|
@ -196,20 +200,20 @@ TEST_F(WireBufferMappingTests, DestroyBeforeReadRequestEnd) {
|
|||
// Unmap was called
|
||||
TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForRead) {
|
||||
dawnCallbackUserdata userdata = 8657;
|
||||
dawnBufferMapReadAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback, userdata);
|
||||
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
uint32_t bufferContent = 31337;
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
&bufferContent);
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, &bufferContent,
|
||||
sizeof(uint32_t));
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
// Oh no! We are calling Unmap too early!
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, userdata))
|
||||
.Times(1);
|
||||
dawnBufferUnmap(buffer);
|
||||
|
||||
|
@ -221,36 +225,37 @@ TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForRead) {
|
|||
TEST_F(WireBufferMappingTests, MappingForReadingErrorWhileAlreadyMappedGetsNullptr) {
|
||||
// Successful map
|
||||
dawnCallbackUserdata userdata = 34098;
|
||||
dawnBufferMapReadAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback, userdata);
|
||||
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
uint32_t bufferContent = 31337;
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
&bufferContent);
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, &bufferContent,
|
||||
sizeof(uint32_t));
|
||||
}))
|
||||
.RetiresOnSaturation();
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)),
|
||||
sizeof(uint32_t), userdata))
|
||||
.Times(1);
|
||||
|
||||
FlushServer();
|
||||
|
||||
// Map failure while the buffer is already mapped
|
||||
userdata++;
|
||||
dawnBufferMapReadAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback, userdata);
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr);
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0);
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata))
|
||||
.Times(1);
|
||||
|
||||
FlushServer();
|
||||
|
@ -259,19 +264,20 @@ TEST_F(WireBufferMappingTests, MappingForReadingErrorWhileAlreadyMappedGetsNullp
|
|||
// Test that the MapReadCallback isn't fired twice when unmap() is called inside the callback
|
||||
TEST_F(WireBufferMappingTests, UnmapInsideMapReadCallback) {
|
||||
dawnCallbackUserdata userdata = 2039;
|
||||
dawnBufferMapReadAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback, userdata);
|
||||
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
uint32_t bufferContent = 31337;
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
&bufferContent);
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, &bufferContent,
|
||||
sizeof(uint32_t));
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)),
|
||||
sizeof(uint32_t), userdata))
|
||||
.WillOnce(InvokeWithoutArgs([&]() { dawnBufferUnmap(buffer); }));
|
||||
|
||||
FlushServer();
|
||||
|
@ -285,19 +291,20 @@ TEST_F(WireBufferMappingTests, UnmapInsideMapReadCallback) {
|
|||
// callback
|
||||
TEST_F(WireBufferMappingTests, DestroyInsideMapReadCallback) {
|
||||
dawnCallbackUserdata userdata = 2039;
|
||||
dawnBufferMapReadAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapReadCallback, userdata);
|
||||
dawnBufferMapReadAsync(buffer, ToMockBufferMapReadCallback, userdata);
|
||||
|
||||
uint32_t bufferContent = 31337;
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
EXPECT_CALL(api, OnBufferMapReadAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
&bufferContent);
|
||||
api.CallMapReadCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, &bufferContent,
|
||||
sizeof(uint32_t));
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapReadCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)), userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(bufferContent)),
|
||||
sizeof(uint32_t), userdata))
|
||||
.WillOnce(InvokeWithoutArgs([&]() { dawnBufferRelease(buffer); }));
|
||||
|
||||
FlushServer();
|
||||
|
@ -310,23 +317,23 @@ TEST_F(WireBufferMappingTests, DestroyInsideMapReadCallback) {
|
|||
// Check mapping for writing a succesfully created buffer
|
||||
TEST_F(WireBufferMappingTests, MappingForWriteSuccessBuffer) {
|
||||
dawnCallbackUserdata userdata = 8653;
|
||||
dawnBufferMapWriteAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapWriteCallback, userdata);
|
||||
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
uint32_t serverBufferContent = 31337;
|
||||
uint32_t updatedContent = 4242;
|
||||
uint32_t zero = 0;
|
||||
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapWriteCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
&serverBufferContent);
|
||||
&serverBufferContent, sizeof(uint32_t));
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
// The map write callback always gets a buffer full of zeroes.
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(zero)), userdata))
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
Pointee(Eq(zero)), sizeof(uint32_t), userdata))
|
||||
.Times(1);
|
||||
|
||||
FlushServer();
|
||||
|
@ -347,17 +354,17 @@ TEST_F(WireBufferMappingTests, MappingForWriteSuccessBuffer) {
|
|||
// writing
|
||||
TEST_F(WireBufferMappingTests, ErrorWhileMappingForWrite) {
|
||||
dawnCallbackUserdata userdata = 8654;
|
||||
dawnBufferMapWriteAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapWriteCallback, userdata);
|
||||
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapWriteCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr);
|
||||
api.CallMapWriteCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0);
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata))
|
||||
.Times(1);
|
||||
|
||||
FlushServer();
|
||||
|
@ -366,13 +373,12 @@ TEST_F(WireBufferMappingTests, ErrorWhileMappingForWrite) {
|
|||
// Check mapping for writing a buffer that didn't get created on the server side
|
||||
TEST_F(WireBufferMappingTests, MappingForWriteErrorBuffer) {
|
||||
dawnCallbackUserdata userdata = 8655;
|
||||
dawnBufferMapWriteAsync(errorBuffer, 40, sizeof(uint32_t), ToMockBufferMapWriteCallback,
|
||||
userdata);
|
||||
dawnBufferMapWriteAsync(errorBuffer, ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata))
|
||||
.Times(1);
|
||||
|
||||
FlushServer();
|
||||
|
@ -386,11 +392,10 @@ TEST_F(WireBufferMappingTests, MappingForWriteErrorBuffer) {
|
|||
// request is finished
|
||||
TEST_F(WireBufferMappingTests, DestroyBeforeWriteRequestEnd) {
|
||||
dawnCallbackUserdata userdata = 8656;
|
||||
dawnBufferMapWriteAsync(errorBuffer, 40, sizeof(uint32_t), ToMockBufferMapWriteCallback,
|
||||
userdata);
|
||||
dawnBufferMapWriteAsync(errorBuffer, ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, userdata))
|
||||
.Times(1);
|
||||
|
||||
dawnBufferRelease(errorBuffer);
|
||||
|
@ -400,20 +405,20 @@ TEST_F(WireBufferMappingTests, DestroyBeforeWriteRequestEnd) {
|
|||
// Unmap was called
|
||||
TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForWrite) {
|
||||
dawnCallbackUserdata userdata = 8657;
|
||||
dawnBufferMapWriteAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapWriteCallback, userdata);
|
||||
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
uint32_t bufferContent = 31337;
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapWriteCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
&bufferContent);
|
||||
&bufferContent, sizeof(uint32_t));
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
// Oh no! We are calling Unmap too early!
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_UNKNOWN, nullptr, 0, userdata))
|
||||
.Times(1);
|
||||
dawnBufferUnmap(buffer);
|
||||
|
||||
|
@ -425,37 +430,37 @@ TEST_F(WireBufferMappingTests, UnmapCalledTooEarlyForWrite) {
|
|||
TEST_F(WireBufferMappingTests, MappingForWritingErrorWhileAlreadyMappedGetsNullptr) {
|
||||
// Successful map
|
||||
dawnCallbackUserdata userdata = 34098;
|
||||
dawnBufferMapWriteAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapWriteCallback, userdata);
|
||||
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
uint32_t bufferContent = 31337;
|
||||
uint32_t zero = 0;
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapWriteCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
&bufferContent);
|
||||
&bufferContent, sizeof(uint32_t));
|
||||
}))
|
||||
.RetiresOnSaturation();
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(zero)), userdata))
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
Pointee(Eq(zero)), sizeof(uint32_t), userdata))
|
||||
.Times(1);
|
||||
|
||||
FlushServer();
|
||||
|
||||
// Map failure while the buffer is already mapped
|
||||
userdata++;
|
||||
dawnBufferMapWriteAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapWriteCallback, userdata);
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapWriteCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr);
|
||||
api.CallMapWriteCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0);
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata))
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, 0, userdata))
|
||||
.Times(1);
|
||||
|
||||
FlushServer();
|
||||
|
@ -464,20 +469,20 @@ TEST_F(WireBufferMappingTests, MappingForWritingErrorWhileAlreadyMappedGetsNullp
|
|||
// Test that the MapWriteCallback isn't fired twice when unmap() is called inside the callback
|
||||
TEST_F(WireBufferMappingTests, UnmapInsideMapWriteCallback) {
|
||||
dawnCallbackUserdata userdata = 2039;
|
||||
dawnBufferMapWriteAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapWriteCallback, userdata);
|
||||
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
uint32_t bufferContent = 31337;
|
||||
uint32_t zero = 0;
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapWriteCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
&bufferContent);
|
||||
&bufferContent, sizeof(uint32_t));
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(zero)), userdata))
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
Pointee(Eq(zero)), sizeof(uint32_t), userdata))
|
||||
.WillOnce(InvokeWithoutArgs([&]() { dawnBufferUnmap(buffer); }));
|
||||
|
||||
FlushServer();
|
||||
|
@ -491,20 +496,20 @@ TEST_F(WireBufferMappingTests, UnmapInsideMapWriteCallback) {
|
|||
// callback
|
||||
TEST_F(WireBufferMappingTests, DestroyInsideMapWriteCallback) {
|
||||
dawnCallbackUserdata userdata = 2039;
|
||||
dawnBufferMapWriteAsync(buffer, 40, sizeof(uint32_t), ToMockBufferMapWriteCallback, userdata);
|
||||
dawnBufferMapWriteAsync(buffer, ToMockBufferMapWriteCallback, userdata);
|
||||
|
||||
uint32_t bufferContent = 31337;
|
||||
uint32_t zero = 0;
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, 40, sizeof(uint32_t), _, _))
|
||||
EXPECT_CALL(api, OnBufferMapWriteAsyncCallback(apiBuffer, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallMapWriteCallback(apiBuffer, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
&bufferContent);
|
||||
&bufferContent, sizeof(uint32_t));
|
||||
}));
|
||||
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback,
|
||||
Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, Pointee(Eq(zero)), userdata))
|
||||
EXPECT_CALL(*mockBufferMapWriteCallback, Call(DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS,
|
||||
Pointee(Eq(zero)), sizeof(uint32_t), userdata))
|
||||
.WillOnce(InvokeWithoutArgs([&]() { dawnBufferRelease(buffer); }));
|
||||
|
||||
FlushServer();
|
||||
|
|
Loading…
Reference in New Issue