diff --git a/src/dawn_native/Buffer.cpp b/src/dawn_native/Buffer.cpp index 9f7239e5aa..57e175a2ab 100644 --- a/src/dawn_native/Buffer.cpp +++ b/src/dawn_native/Buffer.cpp @@ -64,11 +64,13 @@ namespace dawn_native { UNREACHABLE(); return {}; } - void MapReadAsyncImpl(uint32_t serial) override { + MaybeError MapReadAsyncImpl(uint32_t serial) override { UNREACHABLE(); + return {}; } - void MapWriteAsyncImpl(uint32_t serial) override { + MaybeError MapWriteAsyncImpl(uint32_t serial) override { UNREACHABLE(); + return {}; } void UnmapImpl() override { UNREACHABLE(); @@ -244,7 +246,9 @@ namespace dawn_native { mMapUserdata = userdata; mState = BufferState::Mapped; - MapReadAsyncImpl(mMapSerial); + if (GetDevice()->ConsumedError(MapReadAsyncImpl(mMapSerial))) { + return; + } } MaybeError BufferBase::SetSubDataImpl(uint32_t start, uint32_t count, const void* data) { @@ -282,7 +286,9 @@ namespace dawn_native { mMapUserdata = userdata; mState = BufferState::Mapped; - MapWriteAsyncImpl(mMapSerial); + if (GetDevice()->ConsumedError(MapWriteAsyncImpl(mMapSerial))) { + return; + } } void BufferBase::Destroy() { diff --git a/src/dawn_native/Buffer.h b/src/dawn_native/Buffer.h index bcb6a0da52..e656c25c4c 100644 --- a/src/dawn_native/Buffer.h +++ b/src/dawn_native/Buffer.h @@ -82,8 +82,8 @@ namespace dawn_native { private: virtual MaybeError MapAtCreationImpl(uint8_t** mappedPointer) = 0; virtual MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const void* data); - virtual void MapReadAsyncImpl(uint32_t serial) = 0; - virtual void MapWriteAsyncImpl(uint32_t serial) = 0; + virtual MaybeError MapReadAsyncImpl(uint32_t serial) = 0; + virtual MaybeError MapWriteAsyncImpl(uint32_t serial) = 0; virtual void UnmapImpl() = 0; virtual void DestroyImpl() = 0; diff --git a/src/dawn_native/d3d12/BufferD3D12.cpp b/src/dawn_native/d3d12/BufferD3D12.cpp index 331798450d..77f2a77f66 100644 --- a/src/dawn_native/d3d12/BufferD3D12.cpp +++ b/src/dawn_native/d3d12/BufferD3D12.cpp @@ -215,7 +215,7 @@ namespace dawn_native { namespace d3d12 { return {}; } - void Buffer::MapReadAsyncImpl(uint32_t serial) { + MaybeError Buffer::MapReadAsyncImpl(uint32_t serial) { mWrittenMappedRange = {}; D3D12_RANGE readRange = {0, GetSize()}; char* data = nullptr; @@ -225,9 +225,10 @@ namespace dawn_native { namespace d3d12 { // writes available when the fence is passed. MapRequestTracker* tracker = ToBackend(GetDevice())->GetMapRequestTracker(); tracker->Track(this, serial, data, false); + return {}; } - void Buffer::MapWriteAsyncImpl(uint32_t serial) { + MaybeError Buffer::MapWriteAsyncImpl(uint32_t serial) { mWrittenMappedRange = {0, GetSize()}; char* data = nullptr; ASSERT_SUCCESS(mResource->Map(0, &mWrittenMappedRange, reinterpret_cast(&data))); @@ -236,6 +237,7 @@ namespace dawn_native { namespace d3d12 { // writes available on queue submission. MapRequestTracker* tracker = ToBackend(GetDevice())->GetMapRequestTracker(); tracker->Track(this, serial, data, true); + return {}; } void Buffer::UnmapImpl() { diff --git a/src/dawn_native/d3d12/BufferD3D12.h b/src/dawn_native/d3d12/BufferD3D12.h index c4b0fcf261..811fe19103 100644 --- a/src/dawn_native/d3d12/BufferD3D12.h +++ b/src/dawn_native/d3d12/BufferD3D12.h @@ -40,8 +40,8 @@ namespace dawn_native { namespace d3d12 { private: // Dawn API - void MapReadAsyncImpl(uint32_t serial) override; - void MapWriteAsyncImpl(uint32_t serial) override; + MaybeError MapReadAsyncImpl(uint32_t serial) override; + MaybeError MapWriteAsyncImpl(uint32_t serial) override; void UnmapImpl() override; void DestroyImpl() override; diff --git a/src/dawn_native/metal/BufferMTL.h b/src/dawn_native/metal/BufferMTL.h index 4708b44b2d..c4395b2d40 100644 --- a/src/dawn_native/metal/BufferMTL.h +++ b/src/dawn_native/metal/BufferMTL.h @@ -35,8 +35,8 @@ namespace dawn_native { namespace metal { private: // Dawn API - void MapReadAsyncImpl(uint32_t serial) override; - void MapWriteAsyncImpl(uint32_t serial) override; + MaybeError MapReadAsyncImpl(uint32_t serial) override; + MaybeError MapWriteAsyncImpl(uint32_t serial) override; void UnmapImpl() override; void DestroyImpl() override; diff --git a/src/dawn_native/metal/BufferMTL.mm b/src/dawn_native/metal/BufferMTL.mm index b73ff5f11c..d4cb82f1f1 100644 --- a/src/dawn_native/metal/BufferMTL.mm +++ b/src/dawn_native/metal/BufferMTL.mm @@ -57,14 +57,16 @@ namespace dawn_native { namespace metal { return {}; } - void Buffer::MapReadAsyncImpl(uint32_t serial) { + MaybeError Buffer::MapReadAsyncImpl(uint32_t serial) { MapRequestTracker* tracker = ToBackend(GetDevice())->GetMapTracker(); tracker->Track(this, serial, false); + return {}; } - void Buffer::MapWriteAsyncImpl(uint32_t serial) { + MaybeError Buffer::MapWriteAsyncImpl(uint32_t serial) { MapRequestTracker* tracker = ToBackend(GetDevice())->GetMapTracker(); tracker->Track(this, serial, true); + return {}; } void Buffer::UnmapImpl() { diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp index 97ee4e74b4..693cf09fc9 100644 --- a/src/dawn_native/null/DeviceNull.cpp +++ b/src/dawn_native/null/DeviceNull.cpp @@ -264,12 +264,14 @@ namespace dawn_native { namespace null { return {}; } - void Buffer::MapReadAsyncImpl(uint32_t serial) { + MaybeError Buffer::MapReadAsyncImpl(uint32_t serial) { MapAsyncImplCommon(serial, false); + return {}; } - void Buffer::MapWriteAsyncImpl(uint32_t serial) { + MaybeError Buffer::MapWriteAsyncImpl(uint32_t serial) { MapAsyncImplCommon(serial, true); + return {}; } void Buffer::MapAsyncImplCommon(uint32_t serial, bool isWrite) { diff --git a/src/dawn_native/null/DeviceNull.h b/src/dawn_native/null/DeviceNull.h index a6819a8eb7..cff06a0fd5 100644 --- a/src/dawn_native/null/DeviceNull.h +++ b/src/dawn_native/null/DeviceNull.h @@ -151,8 +151,8 @@ namespace dawn_native { namespace null { private: // Dawn API MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const void* data) override; - void MapReadAsyncImpl(uint32_t serial) override; - void MapWriteAsyncImpl(uint32_t serial) override; + MaybeError MapReadAsyncImpl(uint32_t serial) override; + MaybeError MapWriteAsyncImpl(uint32_t serial) override; void UnmapImpl() override; void DestroyImpl() override; diff --git a/src/dawn_native/opengl/BufferGL.cpp b/src/dawn_native/opengl/BufferGL.cpp index 2d6856fcf9..3f54691469 100644 --- a/src/dawn_native/opengl/BufferGL.cpp +++ b/src/dawn_native/opengl/BufferGL.cpp @@ -58,7 +58,7 @@ namespace dawn_native { namespace opengl { return {}; } - void Buffer::MapReadAsyncImpl(uint32_t serial) { + MaybeError Buffer::MapReadAsyncImpl(uint32_t serial) { const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; // TODO(cwallez@chromium.org): this does GPU->CPU synchronization, we could require a high @@ -66,9 +66,10 @@ namespace dawn_native { namespace opengl { gl.BindBuffer(GL_ARRAY_BUFFER, mBuffer); void* data = gl.MapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY); CallMapReadCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data, GetSize()); + return {}; } - void Buffer::MapWriteAsyncImpl(uint32_t serial) { + MaybeError Buffer::MapWriteAsyncImpl(uint32_t serial) { const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; // TODO(cwallez@chromium.org): this does GPU->CPU synchronization, we could require a high @@ -76,6 +77,7 @@ namespace dawn_native { namespace opengl { gl.BindBuffer(GL_ARRAY_BUFFER, mBuffer); void* data = gl.MapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); CallMapWriteCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, data, GetSize()); + return {}; } void Buffer::UnmapImpl() { diff --git a/src/dawn_native/opengl/BufferGL.h b/src/dawn_native/opengl/BufferGL.h index a4baadfaa7..73bc041b93 100644 --- a/src/dawn_native/opengl/BufferGL.h +++ b/src/dawn_native/opengl/BufferGL.h @@ -33,8 +33,8 @@ namespace dawn_native { namespace opengl { private: // Dawn API MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const void* data) override; - void MapReadAsyncImpl(uint32_t serial) override; - void MapWriteAsyncImpl(uint32_t serial) override; + MaybeError MapReadAsyncImpl(uint32_t serial) override; + MaybeError MapWriteAsyncImpl(uint32_t serial) override; void UnmapImpl() override; void DestroyImpl() override; diff --git a/src/dawn_native/vulkan/BufferVk.cpp b/src/dawn_native/vulkan/BufferVk.cpp index 968cb19ddd..e7b3bea1e7 100644 --- a/src/dawn_native/vulkan/BufferVk.cpp +++ b/src/dawn_native/vulkan/BufferVk.cpp @@ -209,7 +209,7 @@ namespace dawn_native { namespace vulkan { return {}; } - void Buffer::MapReadAsyncImpl(uint32_t serial) { + MaybeError Buffer::MapReadAsyncImpl(uint32_t serial) { Device* device = ToBackend(GetDevice()); VkCommandBuffer commands = device->GetPendingCommandBuffer(); @@ -220,9 +220,10 @@ namespace dawn_native { namespace vulkan { MapRequestTracker* tracker = device->GetMapRequestTracker(); tracker->Track(this, serial, memory, false); + return {}; } - void Buffer::MapWriteAsyncImpl(uint32_t serial) { + MaybeError Buffer::MapWriteAsyncImpl(uint32_t serial) { Device* device = ToBackend(GetDevice()); VkCommandBuffer commands = device->GetPendingCommandBuffer(); @@ -233,6 +234,7 @@ namespace dawn_native { namespace vulkan { MapRequestTracker* tracker = device->GetMapRequestTracker(); tracker->Track(this, serial, memory, true); + return {}; } void Buffer::UnmapImpl() { diff --git a/src/dawn_native/vulkan/BufferVk.h b/src/dawn_native/vulkan/BufferVk.h index 20fb9f0853..81d7a4e3ff 100644 --- a/src/dawn_native/vulkan/BufferVk.h +++ b/src/dawn_native/vulkan/BufferVk.h @@ -42,8 +42,8 @@ namespace dawn_native { namespace vulkan { private: // Dawn API - void MapReadAsyncImpl(uint32_t serial) override; - void MapWriteAsyncImpl(uint32_t serial) override; + MaybeError MapReadAsyncImpl(uint32_t serial) override; + MaybeError MapWriteAsyncImpl(uint32_t serial) override; void UnmapImpl() override; void DestroyImpl() override;